2012-02-07 160 views
1

我无法得到某种原因,我只收到了页面ID的页面访问令牌...... 这是我的代码:无法获取页面访问令牌

<html> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js" type="text/javascript"></script> 

</head> 
<body> 
<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
     FB.init({ 
      appId  : 'APP-ID', 
      status  : true, 
      cookie  : true, 
      xfbml  : true, 
      oauth  : true, 
     }); 
    }; 
    (function(d){ 
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} 
     js = d.createElement('script'); js.id = id; js.async = true; 
     js.src = "//connect.facebook.net/en_US/all.js"; 
     d.getElementsByTagName('head')[0].appendChild(js); 
    }(document)); 
</script> 
<div class="fb-login-button" data-scope="email,user_checkins,manage_pages">Login with Facebook</div> 

<div class="result">Start</div> 
<div class="result_app_installed">Start</div> 
<script> 
// Get access token 
$.get('https://graph.facebook.com/102561956524622?fields=access_token', function(data) { 
    alert(data); 
}); 

// Get data if user is application is installed on that page or not. 
$.get("https://graph.facebook.com/102561956524622/tabs/255792581098802", 
    function(data) { 
    alert(data); 
    }); 
</script> 
</body> 
</html> 

我所试图做的是获取页面访问令牌,然后检查是否安装在该页面上的应用程序.. 我在做什么错误?

回答

0

https://graph.facebook.com/102561956524622?fields=access_token
将不起作用。为了得到一个的access_token任何粉丝页面,您需要做的步骤说明如下:

writing on the wall on behalf of my fanpage

而不是使用$不用彷徨,最好使用Facebook的JavaScript SDK的:

https://developers.facebook.com/docs/reference/javascript/

所以对于第二个请求这将是:

FB.api('/102561956524622/tabs/255792581098802', 
function(response) { 

    alert(response); 

}); 

记住,为了使这个FB.api叫您必须授权应用第一

+0

仍然没有工作...我得到不同的错误:“错误校验应用程序” “OAuthException”这是我的代码:http://pastebin.com/YPdeU0tM – DanR 2012-02-07 14:38:53

+1

我觉得你错了代码和accessToken,你不能使用代码作为accessToken,请参考这个文档:https://developers.facebook。 com/docs/authentication/ – 2012-02-08 09:14:56

+0

也可以使用Javascript获取access_token您可以使用http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/方法(如果已连接)返回access_token,如果您调试它你会看到它返回的是什么 – 2012-02-08 09:15:43

2

试着这么做:

FB.api('/me/accounts',function(response) {alert(response);})

页令牌返回的数据的access_token

您需要manage_pages许可。

0

Actuelly它很容易

FB.api('/'+[PAGE_ID]+'?fields=id,likes,name,access_token', function(response) { 
    console.log(response.access_token); 
}); 

不要忘记检查,如果用户登录