我正在尝试使用当前脚本将照片上传到用户的相册:
$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.
我一直在做的是:
以下是完整代码:
$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。
感谢。
答案 0 :(得分:0)
我通过NOT使用内置的$ 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);