在Facebook上上传多张照片时出错:图表返回错误:无效的OAuth访问令牌用于批处理

时间:2018-02-17 19:42:01

标签: php facebook facebook-graph-api

使用批处理在Facebook上传多张图片时出错:

  

图表返回了错误:无效的OAuth访问令牌“。

我可以从登录用户那里获得许可,但无法通过此过程上传多张图片。

include("src/Facebook/Facebook.php");
require_once 'src/Facebook/autoload.php';


$fb = new Facebook\Facebook([
  'app_id' => '<redacted>',
  'app_secret' => '<redacted>',
  'default_graph_version' => 'v2.5'
  ]);
// Since all the requests will be sent on behalf of the same 
 user,
// we'll set the default fallback access token here.
$fb->setDefaultAccessToken('user-access-token');

$batch = [
  'photo-one' => $fb->request('POST', '/me/photos', [
      'message' => 'Foo photo',
      'source' => $fb->fileToUpload('http://localhost/php-
        graph/123.jpg'),

    ]),
  'photo-two' => $fb->request('POST', '/me/photos', [
      'message' => 'Bar photo',
      'source' => $fb->fileToUpload('http://localhost/php-
      graph/123.jpg'),

    ])
];

try {
  $responses = $fb->sendBatchRequest($batch);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

foreach ($responses as $key => $response) {
  if ($response->isError()) {
    $e = $response->getThrownException();
    echo '<p>Error! Facebook SDK Said: ' . $e->getMessage()";
    echo '<p>Graph Said: ' . "\n\n";
    var_dump($e->getResponse());
  } else {
    echo "<p>(" . $key . ") HTTP status code: " . $response-
     >getHttpStatusCode() . "<br />\n";
    echo "Response: " . $response->getBody() . "</p>\n\n";
    echo "<hr />\n\n";
  }
}

0 个答案:

没有答案