Facebook的API为/饲料工作正常,但不能用于/照片(Facebook API works f

2019-07-29 00:13发布

以下是如果我传递的是正常工作的代码/pageid/feedfacebook->api ,但是当我改变它的图像直接上传到我的Facebook相册,它不会工作。 请让我知道我做错了下面的代码:

// Works fine
$status = $facebook->api("/194458563914948/feed", 'post', $attachment);

// Does not work
$status = $facebook->api("/196878530339618/photos", 'post', $attachment);

完整的源

    <?php

require 'src/facebook.php';

$app_id = "332267477347";
$app_secret = "xxxx";

$facebook = new Facebook(array(
 'appId' => $app_id,
 'secret' => $app_secret,
 'cookie' => true,
 'fileUpload' => true,

));

$facebook->setFileUploadSupport(true);  


$user = $facebook->getUser();
//echo $user;

if(($facebook->getUser())==0)
{
 header("Location:{$facebook->getLoginUrl(array('scope' => 'photo_upload,user_status,publish_stream,user_photos,manage_pages'))}");
 exit;
}
else {
$accounts_list = $facebook->api('/me/accounts');
echo "i am connected";
}
  $valid_files = array('image/jpeg', 'image/png', 'image/gif');


//to get the page access token to post as a page
foreach($accounts_list['data'] as $account){
      if($account['id'] == 194458563914948){      // my page id =123456789
        $access_token = $account['access_token'];
        echo "<p>Page -- Access Token: $access_token</p>";
        }
    }

//posting to the page wall

if (isset($_FILES) && !empty($_FILES))
{  
$aid = '421539304540205';
$folder = "pak/".$_FILES['pic']['name'];
$fold = 'http://snowdrop.com.pk/fb/'.$folder;
echo $fold."<br>";
if( move_uploaded_file($_FILES['pic']['tmp_name'], $folder) )
{
#Upload photo here
  $img = realpath($_FILES["pic"]["tmp_name"]);
$attachment = array('message' => $_POST['textfield'],
                           'aid' => $aid,
   'source' => '@' . $img,
                                'access_token' => $access_token,


                );
$status = $facebook->api("/421539304540205/photos", 'post', $attachment);

echo $status;
var_dump($status);

 }
 else{
    echo 'Only jpg, png and gif image types are supported!';

}
}
?>
<body>
 <!-- Form for uploading the photo -->
 <div class="main">
  <p>Select a photo to upload on Facebook Fan Page</p>
  <form method="post" action="" enctype="multipart/form-data">
  <p>Select the image: <input type="file" name="pic" />
    <br />
    <label>Description
    <input type="text" name="textfield" id="textfield" />
    </label>
  </p>
  <p><input class="post_but" type="submit" value="Upload to my album" /></p>
  </form>
 </div>
</body>

Answer 1:

您正在使用/ 406221796071956 /照片的道路是错误的,这就是为什么它不工作。

之所以说这条路是错误的,是406221796071956是图片的ID,看到自己的图形API浏览器为406221796071956说:

“类型”:“照片”

如果你想要发布到该相册,然后使用/ 196878530339618 /照片 ,因为它是专辑: 图形API资源管理器196878530339618

“类型”:“专辑”


编辑

请参考https://developers.facebook.com/docs/reference/api/album/#photos将照片添加到相册。


第二次编辑

根据该的文档, 相册对象 :

can_upload

确定用户身份证明是否可以上传到相册,如果用户拥有专辑返回true,这张专辑是不是满了,应用程序可以将照片添加到相册

所以,你需要的专辑不饱满,是相册的拥有者,并有上载正确的权限。



文章来源: Facebook API works fine for /feed, but not for /photos