开发者

How to fetch user info from Facebook?

I'm working on a PHP/MySQL website. A requirement is that users can either create an account normally, or click to login through facebook, in which case we need to fetch their name, email, and other profile data from facebook and redirect them to the sign up page with their details filled in.

However I have no idea of how this can be done. Can someone please give me a step by step breakdown of how this can be accomplished, including some sample code or relavent links to the documentation, if possi开发者_StackOverflow中文版ble?


You have to use Facebook Connect in order to have Facebook functionality in your web site.

For that, you have to register yourself an application in http://www.facebook.com/developers/ in order to get API Key, Application Secret and Application ID (which are used for authentication purposes)

There are two choices - to use PHP API or to use Javascript API. For the PHP API - I suggest you to check this website http://www.pakt.com/pakt/?id=5e17b48f5679ab47

For the javascript API ( http://developers.facebook.com/docs/reference/javascript/ ), you have to include this javascript file http://connect.facebook.net/en_US/all.js like that :

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
  FB.init({
    appId  : 'YOUR APP ID',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true  // parse XFBML
  });
</script>

With this, you have the very basic functionality of Facebook Connect in your page. I suggest to go to the Facebook Docs and read for more methods and API calls. How to login person How to determine if user is connected And much more - http://developers.facebook.com/docs/reference/javascript/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜