我开始构建一个 facebook 扩展应用程序。我得到了 api auth 部分工作。 现在当我使用 javascript api 请求任何东西时,我无法做到。
例如:
<div id="profile_pics"></div>
<script type="text/javascript">
var widget_div = document.getElementById("profile_pics");
FB.ensureInit(function () {
FB.Facebook.get_sessionState().waitUntilReady(function() {
FB.Facebook.apiClient.friends_get(null, function(result) {
var markup = "";
var num_friends = result ? Math.min(5, result.length) : 0;
if (num_friends > 0) {
for (var i=0; i<num_friends; i++) {
markup +=
'<fb:profile-pic size="square" uid="'+result[i]+'" facebook-logo="true"></fb:profile-pic>';
}
}
widget_div.innerHTML = markup;
FB.XFBML.Host.parseDomElement(widget_div);
});
});
});
</script>
上面的示例代码应该显示我 friend 的方形缩略图。它只显示带有 facebook Logo 的方形拇指 (BLANKS)。我哪里错了?
仅供引用: 我有位于本地主机的文件。在 facebook 应用程序设置中,我将连接 url 作为“localhost/dir/index.html”url 的地址。我做错了什么吗? 请帮助我。
编辑 这是我用来登录的代码:
<script type="text/javascript">
//<![CDATA[
var api_key = 'myapikey';
var channel_path = '/xd_receiver.htm';
FB_RequireFeatures(["Api"],
function(){
// Create an ApiClient object, passing app's API key and
// a site relative URL to xd_receiver.htm
FB.Facebook.init(api_key, channel_path);
var api = FB.Facebook.apiClient; // require user to login
api.requireLogin(function(exception)
{
FB.FBDebug.logLevel=1;
FB.FBDebug.dump("Current user id is " + api.get_session().uid);
// Get friends list
//5-14-09: this code below is broken, correct code follows //
//api.friends_get(null, function(result){
// Debug.dump(result, 'friendsResult from non-batch execution ');
// });
api.friends_get(new Array(), function(result, exception){
FB.FBDebug.dump(result, 'friendsResult from non-batch execution ');
});
});
});
//]]>
最佳答案
您发布的示例代码运行良好...我刚刚在我开发的一个 FB 应用程序中对其进行了测试,它创建了我 friend 的个人资料照片。
您可能希望将 console.log(result)
放入您的代码中,并使用 Firebug 检查 API 调用的结果。也许它会给您一条错误消息。在我看来这里可能存在问题,因为在没有有效 uid
的情况下创建的 fb:profile-pic
会显示一个空白方 block 。
我会仔细检查您在“连接 URL”设置下提供给应用程序的 URL 是否是 Facebook 可以访问的有效 URL。还要仔细检查您为 xd_reciever.htm 文件提供的路径是否有效。第三件值得仔细检查的事情是您在文档中设置了正确的 xml 命名空间:
<html xmlns:fb="http://www.facebook.com/2008/fbml" xml:lang="en" lang="en">
关于javascript - 无法通过 Facebook 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1898092/