我在Facebook上发布的代码,如果用户没有登录并且第一次调用此图像,则不会发布图像。在第二次登录时它工作正常,意味着它要求用户访问权限和所有。
window.fbAsyncInit = function() {
FB.init({appId: '********', status: true, cookie: true, xfbml: true, oauth : true});
}
$(document).on('click','#share_facebook',function()
{
// alert('fb_share click');
$('.description').css('display', 'none');
$('#step5_fb_share').css('display', 'block');
});
$(document).on('click','#postonfb',function()
{
//alert('Post On fb'+$('#fb_wall_msg').val());
msgtopost=$('#fb_wall_msg').val();
FB.getLoginStatus(function(response) {
alert('page '+response.status);
if (response.status === 'connected') {
alert(response.authResponse.accessToken);
testAPI();
// connected
} else if (response.status === 'not_authorized') {
// not_authorized
login();
} else {
// not_logged_in
//alert('Not logged in'); FB.login();
login();
}
});
});
// Here we run a very simple test of the Graph API after login is successful.
// This testAPI() function is only called in those cases.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
var postMSG = msgtopost;
//var filename = 'board_download/image.png';
var filename = 'http://alpha.probytes.net/Khet/board_download/image.png';
FB.api('/me/photos', 'post', {
message:postMSG,
url:filename
}, function(response){
if (!response || response.error)
{
alert('Post Failed !! ');
}
else
{
//alert('Post Successfully !! ' + response.id);
alert('Post Successfully !! ');
}
}
);
}
function login()
{
FB.login(function(response) {
if (response.authResponse) {
testAPI();
} else {
console.log('User cancelled login or did not fully authorize.'+response.authResponse);
}
}, {scope: 'publish_stream'});
}