【问题标题】:Publishing Photo on Fan Page album在粉丝专页相册上发布照片
【发布时间】:2013-12-12 01:41:19
【问题描述】:

我有一个 PHP 脚本,可以在我的 Facebook 粉丝专页墙上上传图片+描述+其他详细信息。 但我需要的是在相册中上传。 我在整个互联网上寻找这个答案,this tutorial 是我迄今为止得到的最接近的答案。

这是我的代码:

$params = array(
    "access_token"  => $page_token,
    "message"       => "#php #facebook",
    "link"          => "www.domain.com.br",
    "description"   => "Buy this now!",
    "source"        => "@" . $path,
);

try {
  $ret = $fb->api('/'.$album_id . '/photos', 'POST', $params);
  echo 'Successfully posted to Facebook Fan Page';
} catch(Exception $e) {
  echo $e->getMessage();
}

我已经尝试将这个 $ret = $fb->api('/'.$fanpage_id . '/photos', 'POST', $params); 路径更改为这个:$ret = $fb->api('/'.$fanpage_id.'/'.$album_id . '/photos', 'POST', $params); 和类似的东西。

但它返回 (#240) The target_id references an inactive user 因为 fb API 认为 $album_id$fanpage_id

如果有人知道如何在相册中张贴图片,请帮助我;)

【问题讨论】:

    标签: php facebook facebook-graph-api upload facebook-page


    【解决方案1】:

    就是这样,这段代码检查你想要的专辑是否存在,如果不存在则创建一个新的:

    //Check if the album exists just change PAGE_ID to the ID of your page and NAME_OF_YOUR_ALBUM to the name of the album where you want to upload the photo
    $fql = "SELECT object_id FROM album WHERE owner = PAGE_ID AND name='NAME_OF_YOUR_ALBUM'";
    $album_exists = $this->facebook->api(array(
        'method' => 'fql.query',
        'query' =>$fql,
        'access_token' => $accessToken
    ));
    if(array_key_exists(0, $album_exists)){
        //the album with that name exists, let's save his ID
        $album_uid = $album_exists[0]['object_id'];
    }else{
        //We don't have an album with that name, let's create an album
        $album_details = array('name'=> 'NAME_OF_YOUR_ALBUM');
        $create_album =  $this->facebook->api('/'.$page_id.'/albums', 'post', $album_details);
        //Get album ID of the album you've just created
        $album_uid = $create_album['id'];
    }
    //details of the photo you want to upload
    $photo_details = array('message'=> 'This is a fantastic photo');
    $file='PATH_TO_YOUR_FILE/NAME_FILE.jpg'; //Example image file
    $photo_details['image'] = '@' . realpath($file); //get the real path
    //Upload the photo to the album you've just created or the one you wanted
    $upload_photo =  $this->facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);
    

    【讨论】:

    • Fabio,此代码非常适合 facebook 用户,这不是我需要的。我需要一个几乎像 FANPAGES 上发布的代码。我将访问令牌更改为粉丝页面令牌,并将路径'/me/albums' 更改为'/'.$page_id.'/albums',但它返回了这个错误Impersonated access tokens can only be used with the Graph API。你知道如何对粉丝专页做同样的事情吗?
    • 您是如何检索到该令牌的?并且对于/me/albuns的错字感到抱歉
    • 我发现this video 解释了如何获取令牌
    • 您无法从图形 api 复制令牌,这就是您收到该错误的原因。每次用户进入您的应用时,您都必须获取令牌,如果您需要它的时间超过 2 小时,只需将其换成 60 天的令牌
    • 伙计,我弄错了$album_id 你能相信吗?惭愧我哈哈,谢谢兄弟o/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-08
    • 2011-07-27
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 2012-06-10
    相关资源
    最近更新 更多