【问题标题】:Facebook Graph API: how to add a caption to an image you upload?Facebook Graph API:如何为您上传的图片添加标题?
【发布时间】:2012-02-24 09:37:53
【问题描述】:

我正在尝试将图像发布到 facebook 上的相册并在图像中添加描述。 我可以将图片上传到相册,但我似乎无法添加说明。

这是我使用的代码:

// prepare the curl post fields
$batch = sprintf('[{"method":"POST", "relative_url":"%1$s/photos", "attached_files":"file1", "message":"caption"}]', $album_id);  

$post_fields = array(
'batch' => $batch,
'access_token' => $access_token,
'file1' => '@' . $image_abs_path,
'caption' => 'image caption goes here"
);
$uri = 'https://graph.facebook.com';

$curl = curl_init( $uri );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );  
curl_setopt( $curl, CURLOPT_POST, TRUE );
curl_setopt( $curl, CURLOPT_POSTFIELDS, $post_fields );  

$raw_data = curl_exec( $curl );
curl_close( $curl );

$data = json_decode( $raw_data, $assoc = TRUE );

我也尝试了一个名为“name”的后置字段,但是当我使用它时,我得到一个空数组。当我使用这个帖子字段时,图像不会添加到相册中。

【问题讨论】:

    标签: php facebook facebook-graph-api facebook-apps


    【解决方案1】:

    尝试更改您的 $batch:

    $batch = sprintf('[{"method":"POST", "relative_url":"%1$s/photos", "attached_files":"file1", "body" : "message=Your image caption"}]', $album_id);

    参考:Batch Upload 希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多