首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >访问令牌仍然有效2个月,但API响应显示#2500

访问令牌仍然有效2个月,但API响应显示#2500
EN

Stack Overflow用户
提问于 2013-06-26 09:22:07
回答 1查看 108关注 0票数 0

我正试图用当前脚本将一张照片上传到用户的相册:

代码语言:javascript
运行
复制
$this->facebook->api('/me/photos?access_token='.$user->access_token, 'post', $args);

$user-> access _token是用户的访问令牌,我通过工具进行检查,它说仍然有效(直到2个月)。

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

代码语言:javascript
运行
复制
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更新为最新版本

以下是完整的代码:

代码语言:javascript
运行
复制
    $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);
    }

有什么帮助吗?

如果我用的是码点火器。事实上,我几个小时前就在尝试(它成功了),但是,现在没有了,因为有了access_token。

谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-06-27 07:10:12

我通过不使用内置$facebook->api()手动解决了这个问题,但我现在使用curl。

代码语言:javascript
运行
复制
$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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17316179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档