2

我正在尝试发出批量请求以在不同页面上发布独特的照片。

为此,我希望使用批量发布请求来优化流程。

我的代码:

    $facebook = new Facebook(array('appId' => myappId, secret => mysecret, 'cookie' => true, 'fileUpload' => true, 'domain' => $_SERVER['SERVER_NAME']));

    $request[0] = array( 
        'relative_url' => 'facebookPageId1/photos'
        'method' => 'post' 
        'body' => 'access_token=page_access_token_1&message=my_message&attached_files=' . basename($picture));

    $request[1] = array(
      'relative_url' =>'facebookPageId2/photos'
      'method' => 'post'
      'body' => 'access_token=page_access_token_2&message=my_message&attached_files=' . basename($picture));

    $file[basename($picture)] = '@' . realpath($picture);
    $batch = json_encode(array_values(requests));
    $params = array('batch' => $batch);
    $params = array_merge($params, $file);

    $facebook->api('/', 'POST', $params)

现在,当我运行此代码时,我的两个请求得到了以下输出:

'{"error":{"message":"(#324) Requires upload file","type":"OAuthException","code":324}}'

所以有什么问题 ?

我在我的 Facebook 对象上将fileUpload设置为 true,并尝试在 URL“ pageId/photos ”上发布一张带有经典请求的照片,并且效果很好。但是女巫一个批处理请求,我总是同样的错误。

谢谢你的帮助。

编辑:好的,我弄错了,我的请求是错误的:

$request[0] = array( 
    'relative_url' => 'facebookPageId1/photos',
    'method' => 'post',
    'body' => 'access_token=page_access_token_1&message=my_message',
    'attached_files' => basename($picture)
);

$request[1] = array(
  'relative_url' =>'facebookPageId2/photos',
  'method' => 'post',
  'body' => 'access_token=page_access_token_2&message=my_message',
  'attached_files' => basename($picture)
);

但现在我收到以下错误:

{"error":{"message":"File picturename.jpg has not been attached","type":"GraphBatchException"}}
4

1 回答 1

0

这就是我所做的:

$files['access_token']=$access_token;
$request[0] = array( 
    'relative_url' => 'facebookPageId1/photos',
    'method' => 'POST',
    'body' => 'message=my_message',
    'attached_files' => 'file_0'
);
$files['file_0']= basename($picture);

$batchresult = $facebook->api("/?batch=".urlencode(json_encode($request)), 'POST', $files);

Facebook Batch 要求您将文件放入不同的数组中,您也可以将访问令牌放入其中,您需要放入一次。

于 2013-04-15T23:09:53.837 回答