使用fb js sdk制作封面照片

时间:2014-12-03 12:51:41

标签: javascript facebook

嘿伙计们我决定在facebook上申请。所以我决定继续使用js sdk。

我想通过sdk添加图片作为封面图片。所以我遇到了sdk doc

我试过的代码。

<!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>

此代码实际上工作正常。但它不允许我将图像作为封面照片发布。

任何人都可以告诉我该怎么做..任何帮助将不胜感激。谢谢

1 个答案:

答案 0 :(得分:2)