且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用fb js sdk制作封面图片

更新时间:2023-12-06 15:57:58

您不能通过Graph API发布封面照片。



请参阅




Hey guys i have decided to make an application in facebook.So i have decided to go on with js sdk.

I want to add an image as a cover pic via sdk.So i have came across sdk doc.

The code which i have tried.

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<script>
var c = document.getElementById('boom');

function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);

if (response.status === 'connected') {
  // Logged into your app and Facebook.
  testAPI();
} else if (response.status === 'not_authorized') {

  document.getElementById('status').innerHTML = 'Please log ' +
    'into this app.';
} else {

  document.getElementById('status').innerHTML = 'Please log ' +
    'into Facebook.';
}


}

  function checkLoginState() {
FB.getLoginStatus(function(response) {
  statusChangeCallback(response);
});


}



  window.fbAsyncInit = function() {
  FB.init({
appId      : '289533237896176',
cookie     : true,  

xfbml      : true,  
version    : 'v2.1'
  });





  FB.getLoginStatus(function(response) {
statusChangeCallback(response);
  });
  };





  (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/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));




  function testAPI() {
var imgURL="http://farm4.staticflickr.com/3332/3451193407_b7f047f4b4_o.jpg";

FB.api('/album_id/photos', 'post', {
message:'photo description',
url:imgURL        
}, function(response){


if (!response || response.error) {
    alert('Error occured');
} else {
    alert('Post ID: ' + response.id);
}


});




}



</script>



<fb:login-button scope="public_profile,email,publish_actions" onlogin="checkLoginState();">
</fb:login-button>



<div id="status">
</div>



</body>
</html>

This code works fine actually..But it doesnt allow me to post the image as cover photo.

Can anyone tell me how to do this ..Any help would be appreciated..Thanx

You cannot post the Cover photo via the Graph API.

See