由于某些原因我无法获取页面访问令牌我只收到页面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 :(得分:2)
尝试类似:
FB.api('/ me / accounts',function(response){alert(response);})
Page令牌作为access_token
返回数据您需要manage_pages权限。
答案 1 :(得分:0)
https://graph.facebook.com/102561956524622?fields=access_token
不行。为获取任何粉丝页面的access_token您需要执行此处说明的步骤:
writing on the wall on behalf of my fanpage
不使用$ .get,最好使用Facebook JavaScript SDK:
https://developers.facebook.com/docs/reference/javascript/
所以对于第二个请求,它将是:
FB.api('/102561956524622/tabs/255792581098802',
function(response) {
alert(response);
});
请记住,为了进行此FB.api调用,您需要首先授权该应用
答案 2 :(得分:0)
Actuelly很容易
FB.api('/'+[PAGE_ID]+'?fields=id,likes,name,access_token', function(response) {
console.log(response.access_token);
});
别忘了检查用户是否已登录。