Facebook API - 用户对象返回奇怪的值
我有一个 用户对象,但它的唯一属性是 education、first_name 、id、姓氏、链接、区域设置、位置、名称、时区、更新时间、已验证
。这不仅缺少应该公开的属性(例如 picture
),而且这些值也与文档不同(updated_time
与 last_updated
) 。最后,奇怪的是,我从文档页面上的链接得到了同样的结果(此处)。最终,我试图获取user.feed
。
任何有关正在发生的事情的想法将不胜感激。我错过了一些明显的东西吗?
访问 https://graph.facebook.com/me/feed 会显示以下内容:
{“错误”:{ “类型”:“OAuthException”, "message": "必须使用活动访问令牌才能查询 有关当前用户的信息。”
} }
为什么我需要活动访问令牌? 文档说图片
和feed
是公开的!
这是代码。 user
对象被记录到 Firebug.console:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
<script type="text/javascript">
function update_user_box() {
var user_box = document.getElementById("user");
FB.api('/me', function(user) {
user_box.innerHTML = "<fb:profile-pic uid=\"loggedinuser\" useyou=\"false\"></fb:profile-pic>"
+ "Hey " + user.first_name + "<br>";
FB.XFBML.parse();
console.log(user);
});
}
</script>
</head>
<body>
<div id='user'><fb:login-button onlogin="update_user_box();"></fb:login-button></div>
<br><br>
<div id="fb-root"></div>
<script>
FB.init({
appId : 'b07e858317c9069d450023b7500b4511',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.session) {
update_user_box();
} else {
// no user session available, someone you dont know
}
});
</script>
</body>
</html>
I have a user object, but it's only properties are education, first_name, id, last_name, link, locale, location, name, timezone, updated_time, verified
. Not only is this missing properties that should be public (like picture
), but also these values are different from the documentation (updated_time
vs last_updated
). Finally, strangely, I get the same thing from the link on the documentation page (here). Ultimately, I'm trying to get user.feed
.
Any ideas about what's going on will be greatly appreciated. Am I missing something obvious?
visiting https://graph.facebook.com/me/feed gives the following:
{ "error": {
"type": "OAuthException",
"message": "An active access token must be used to query
information about the current user."
} }
Why do I need an active access token? the docs say that picture
and feed
are public!
Here is the code. The user
object is logged to Firebug.console:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
<script type="text/javascript">
function update_user_box() {
var user_box = document.getElementById("user");
FB.api('/me', function(user) {
user_box.innerHTML = "<fb:profile-pic uid=\"loggedinuser\" useyou=\"false\"></fb:profile-pic>"
+ "Hey " + user.first_name + "<br>";
FB.XFBML.parse();
console.log(user);
});
}
</script>
</head>
<body>
<div id='user'><fb:login-button onlogin="update_user_box();"></fb:login-button></div>
<br><br>
<div id="fb-root"></div>
<script>
FB.init({
appId : 'b07e858317c9069d450023b7500b4511',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.getLoginStatus(function(response) {
if (response.session) {
update_user_box();
} else {
// no user session available, someone you dont know
}
});
</script>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试执行以下几项操作来
我希望这些将帮助您调试。
编辑:
我们遇到了一个问题,即我们使用旧的 API (FB-connect) 并尝试获取扩展权限中提到的数据。由于某种原因,我们无法做到这一点。我们切换到oAuth2.0,并且它起作用了。 #3 要点只是分享我的经验。
此外,对于照片,我们只是从 http://graph.facebook.com/{user_id}/picture 获取数据
There are a couple of things that you can try
I hope these will help you debugging.
Edit:
We faced a problem where we were using old API (FB-connect) and trying to get data mentioned in extended permission. We were not able to -- for some reason. We switched to oAuth2.0, and it worked. #3 bullet was just to share my experience.
Also, for photos we just fetched data from http://graph.facebook.com/{user_id}/picture
从用户处获取离线访问的权限。
供稿
https://graph.facebook.com/{ID@username}/feed/
Get permission from user for offline_access.
Feed
https://graph.facebook.com/{ID@username}/feed/