0

我正在尝试使用当前脚本将照片上传到用户的相册:

$this->facebook->api('/me/photos?access_token='.$user->access_token, 'post', $args);

$user->access_token 是用户的访问令牌,我通过 Facebook Graph API Explorer 工具检查它说仍然有效(直到 2 个月)。

但是,如果我使用上面的脚本创建 API 请求,我的控制台总是返回:

Fatal error:  Uncaught OAuthException: An active access token must be used to query information about the current user.

我一直在做的是:

  • 取消授权应用
  • 重新授权应用
  • 请求权限(publish_stream、photo_upload、user_photos)
  • 更新 FB SDK 到最新版本

这是完整的代码:

    $user = $this->User_model->get_access_token($this->input->post('fb_id'));

    foreach($this->input->post('media') as $media_id)
    {
        $media = $this->Media_model->get_media($media_id);

        $args = array('message' => 'Photo Caption');
        $args['image'] = '@' . realpath(FCPATH.'uploads/booth_1/'.$media->file);

        $data = $this->facebook->api('/me/photos?access_token='.$user->access_token, 'post', $args);
        print_r($data);
    }

有什么帮助吗?

仅供参考,我正在使用 codeigniter。实际上,我在几个小时前就尝试过(它有效),但是现在不是,因为 access_token。

谢谢。

4

1 回答 1

0

我通过不使用内置 $facebook->api() 手动解决了它,但我使用 curl 代替。

$filename = '@' . realpath(FCPATH.'uploads/'.$media);
$url = "https://graph.facebook.com/".$user->fb_id."/photos";

$ch = curl_init($url);

$attachment =  array('access_token' => $user->access_token,
                'app_id'            => APP_ID,
                'name'              => "Upload",
                'fileUpload'        => true,
                'message'           => "Message",
                'image'             => $filename,
          );

curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_CAINFO, PATH TO FB SDK CERT FOR SSL);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

$result = curl_exec($ch);

if ($result === FALSE) {
    die("Curl failed: " . curl_error($ch));
}

curl_close ($ch);
于 2013-06-27T07:10:12.880 回答