我正在构建一个Web应用程序,我需要将其与facebook连接。我的最终目标是将图片发布到用户墙和相册,但我已经打了砖墙。
当使用我自己的app_id
(我自己,我的意思是我用我自己的脸书帐户创建了这个'测试'应用程序)时,它运作得很好 - 图片发布在用户墙和专辑上。但是当使用客户端app_id
(客户端使用他们自己的帐户创建此应用程序,我在那里作为开发人员列出)时,它的行为方式不同 - 用户墙上没有发布图片。
我检查了设置,它们是一样的。代码,相同。我在发布图片时从Facebook获得的回复 - 不同。
这是我正在使用的代码:
<button>share photo</button>
<div id="fb-root"></div>
<script>
var graph_url = 'https://graph.facebook.com/me/photos?access_token=';
var photo_url = '<?php echo $photo_url; ?>';
var user_id = null;
var access_token = null;
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '<?php echo $app_id; ?>', // App ID from the app dashboard
channelUrl : '//my-website/channel.php', // Channel file for x-domain comms
status : true, // Check Facebook Login status
xfbml : true // Look for social plugins on the page
});
// Additional initialization code such as adding Event Listeners goes here
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
user_id = response.authResponse.userID;
access_token = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// nothing to do
} else {
FB.login(function(response) {
if (response.authResponse) {
user_id = response.authResponse.userID;
access_token = response.authResponse.accessToken;
}
});
}
});
$('button').on('click', function(ev) {
if (user_id && access_token) {
FB.api('/me/photos', 'post', {
url: photo_url,
message: 'dasdad',
access_token: access_token
}, function(response) {
console.log(response); // <---- this different
});
}
});
};
// Load the SDK asynchronously
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
此代码记录id
和post_id
(与我的app_id
一样)或仅id
(与客户app_id
)。我完全迷失在这里,有人能指出我正确的方向吗?我在这做错了什么?这是facebook上的错误吗?
答案 0 :(得分:1)
我在登录时没有看到你要求任何权限 - 所以我认为你的应用程序可能仍然具有该权限,因为你之前提供过,但另一个应用程序没有。
请将访问令牌记录到两个应用的浏览器控制台,然后在此处查看https://developers.facebook.com/tools/debug