使用Javascript获取Facebook用户个人资料数据 [英] Getting an Facebook user profile data with Javascript
问题描述
我需要通过Javascript获取一个Facebook用户uid,性别,照片和其他个人资料。
I need to get a facebook user uid , gender, photo and other profile data with Javascript.
我记得有一种方法来获取用户对象。 id,.gender,.photo,但是没有API调用的副本,我在文档中找不到解释。
I remember there was a method to get an user object with .id, .gender, .photo but I haven't got a copy of the API call and I can't find an explanation in the documentation.
用户UID和性别与Javascript?
How do I get the user UID and gender with Javascript ?
谢谢
推荐答案
strong>更新:我添加了一些更多的细节答案:
Update: I added a little more detail to the answer:
首先,您需要调用FB.init并添加您的应用程序ID: p>
First, you need to call FB.init and add your app id:
FB.init(
{
appId : APP_ID,
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
接下来,检查是否有一个会话打开(即用户登录)
Next, check if there is a session open (i.e., the user is logged in)
if(FB.getSession() != null) {
通过以下方式查询详细信息:
And query the details by:
FB.api('/me', function(response)
{
alert ("Welcome " + response.name + ": Your UID is " + response.id);
});
}
您还需要添加< div id =fb-root>< / div>
到您的页面的< body>
,并加载< script src =http://connect.facebook.net/en_US/all.js>< / script>
You will also need to add <div id="fb-root"></div>
to the <body>
of your page, and load <script src="http://connect.facebook.net/en_US/all.js"></script>
用户个人资料图片可以作为 http:/graph.facebook.com/USERID/picture /
The user profile picure can be accessed as http:/graph.facebook.com/USERID/picture/
在此查看Graph API参考: http://developers.facebook.com/docs/参考/ api / user /
Check the Graph API reference here: http://developers.facebook.com/docs/reference/api/user/
和FB SDK参考文献: http://developers.facebook.com/docs/reference/javascript/
and the FB SDK reference here: http://developers.facebook.com/docs/reference/javascript/
这篇关于使用Javascript获取Facebook用户个人资料数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!