【问题标题】:Long lived access token photo posting bug长寿命访问令牌照片发布错误
【发布时间】:2012-12-18 20:11:13
【问题描述】:

我使用长期存在的access_token(2 个月)在 Facebook 粉丝页面上发布内容。

所以我使用以下内容发布文本(成功):

$params = array(
                'access_token' => 'token',
                'message'=> ":-) <3",
                'image' => '@' . $image['file']
);

$post_id = $facebook->api('/'.$page_id.'/feed','post',$params);

还有这个用于在相册中发布照片的代码

$facebook->setFileUploadSupport(true);
$image['file'] = 'images/rezultate/facebook_photo_170439606380900.jpg';
$args = array( 'access_token' => 'token', 'message' => ':-) <3', 'no_story' => 0);
$args['image'] = '@' . $image['file'];
$target_url = "https://graph.facebook.com/356048711158011/photos";

$ch = curl_init(); 
curl_setopt ($ch,CURLOPT_URL,$target_url); 
curl_setopt ($ch, CURLOPT_POST, 1); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_exec($ch);
curl_close ($ch);

问题是:为什么使用 长期访问令牌我无法发布照片?只有文字,但如果我使用 2 小时(短期)访问令牌,我可以发布照片

【问题讨论】:

  • 您收到什么错误信息?其他请求是否有效?
  • 没有错误....长访问仅发布文本

标签: php facebook facebook-graph-api


【解决方案1】:

您必须使用从该扩展用户令牌收到的页面令牌。 从头开始按步骤操作:

  1. 转到Graph API Explorer
  2. 在右上角的应用程序菜单中选择您的应用程序
  3. 获取访问令牌(短期令牌)。
  4. 使用上述令牌生成长期访问令牌(2 个月):

     graph.facebook.com/oauth/access_token?client_id=APP_ID& client_secret=APP_SECRET& grant_type=fb_exchange_token& fb_exchange_token=EXISTING_ACCESS_TOKEN
    
  5. 现在使用这个访问令牌并调用“/me/accounts”
  6. 在结果中,复制与您的页面对应的访问令牌
  7. 通过Debugger检查此令牌的有效性。此页面令牌永不过期。

将此令牌与您的代码一起使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-14
    • 2014-11-24
    • 1970-01-01
    • 2017-07-12
    • 1970-01-01
    • 2012-05-25
    • 2018-11-18
    • 1970-01-01
    相关资源
    最近更新 更多