0

我希望我的应用程序发布照片,用户已经使用 publish_stream 权限注册了我的应用程序,并且当前与 facebook 断开连接。

文档https://developers.facebook.com/docs/publishing/说:

要发布您需要的“照片”对象

  • 有效的访问令牌
  • 发布流权限

我尝试了一个 HTTP POST 请求: https://graph.facebook.com/<USER_ID>/photos?access_token=<APPLICATION_ACCESS_TOKEN>
POST param : "url":"<link_to_some_picture>"

我有一个例外: content={"error":{"message":"A user access token is required to request this resource.","type":"OAuthException","code":102}}

要代表用户发布照片,我无法传递用户访问令牌...为什么我可以发布链接但不能使用我的应用程序访问令牌发布照片?

4

3 回答 3

0

您的标题表明您正在使用应用程序访问令牌 - 您收到的错误清楚地说明了问题。您需要一个用户访问令牌。

您需要扩展您的用户访问令牌,以便在他们未连接到 Facebook 时代表他/她执行操作。

这是有关处理过期令牌以及如何刷新它们的信息的好资源 -

https://developers.facebook.com/docs/authentication/access-token-expiration/

于 2012-07-17T08:49:45.480 回答
0

当用户注册您的应用程序时,您可以使用该访问令牌代表用户发布后存储用户的用户访问令牌。当用户下次访问您的应用程序时,您可以更新该访问令牌。您可以使用以下函数来获取扩展访问令牌:

public function getExtendedAccessToken(){

    try {
        // need to circumvent json_decode by calling _oauthRequest
          // directly, since response isn't JSON format.
        $access_token_response =
            $this->_oauthRequest(
                $this->getUrl('graph', '/oauth/access_token'),
                $params = array(    'client_id' => $this->getAppId(),
                                    'client_secret' => $this->getApiSecret(),
                                    'grant_type'=>'fb_exchange_token',
                                    'fb_exchange_token'=>$this->getAccessToken(),
                              ));

    } catch (FacebookApiException $e) {
      // most likely that user very recently revoked authorization.
      // In any event, we don't have an access token, so say so.
      return false;
    }

    if (empty($access_token_response)) {
      return false;
    }

    $response_params = array();
    parse_str($access_token_response, $response_params);
    if (!isset($response_params['access_token'])) {
      return false;
    }

    return $response_params['access_token'];
}
于 2012-07-18T07:43:43.600 回答
0
$fid = $row[1];
        echo "fid = $fid\n";
        $message =$row[2];
        echo "msg = $message\n";
        $friends = $facebook->api("/$user/friends?fields=id");
        $args= array(

                'app_id' => $facebook->getAppId(),
                'to' => $fid,
                'link' => 'http://www.facebook.com',
                'message'=>$message,

        );
        $post_id = $facebook->api('/fid /feed', 'POST', $args);
        var_dump($post_id);
于 2012-07-25T12:48:30.667 回答