1

I am currently posting images URLs on different facebook pages but I am using many calls to do the same thing.

Instead of this, I am trying to work on a batch request to save on execution time but I have an issue.

Doing many calls, I use this:

$urlLink = '/' . $pageId . '/photos';

$args = array(
    'url'                    => $this->image_url,
    'message'                => $this->message,
    'published'              => false,
    'scheduled_publish_time' => strtotime($this->programmed_dt),
);
$res = $this->fb->api($urlLink, 'POST', $args);

It works fine.

With the batch request I tried with that:

$urlLink = '/' . $facebookPage['id'] . '/photos';
$args['access_token'] = $facebookPage['access_token'];
$queries[] = array('method'       => 'POST',
                   'relative_url' => $urlLink,
                   'body'         => $args,
                   'url' => $this->image_url
);

$res = $this->fb->api('?batch=' . json_encode($queries), 'POST');

The response I have is:

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

I tried to change the name field with all possibilities to send the image link, without success...

Any ideas for batch requests with image urls?

gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
zeflex
  • 1,487
  • 1
  • 14
  • 29

2 Answers2

0

According to https://developers.facebook.com/docs/graph-api/making-multiple-requests/#multiple_methods I assume that your code which forms the request doesn't have the correct syntax.

From my point of view it should be the following:

$args['access_token'] = $facebookPage['access_token'];
$queries[] = array('method'       => 'POST',
                   'relative_url' => $urlLink,
                   'body'         => 'url=' . $this->image_url
);

$res = $this->fb->api('/?batch=' . json_encode($queries) . '&access_token=' . $args['access_token'], 'GET');
Tobi
  • 31,405
  • 8
  • 58
  • 90
  • 1
    Where do you send each page token ? Because we have the main token (user) but to be able to post to pages, I need to send the page token also (got them from /me/accounts). – zeflex Jul 02 '14 at 14:24
  • You can add access token to each request of the batch, see https://developers.facebook.com/docs/graph-api/making-multiple-requests/#differentaccesstokens It need to be added to the body parameter. The "outside" access token is then the fallback access token. – Tobi Jul 02 '14 at 14:33
  • I will try this later and I'll give u some news. Thanks. – zeflex Jul 02 '14 at 15:10
  • Still getting "(#324) Requires upload file" issue. Can we send image urls in batch requests instead of uploading files? I know without batch, yes it's possible. – zeflex Jul 03 '14 at 16:03
0

I can see everything ok in your code except this-

You should set upload support to true before posting image.

$this->fb->setFileUploadSupport(true);

for more detail you can check this answer:

CHECK HERE

Community
  • 1
  • 1
Shail Paras
  • 1,125
  • 1
  • 14
  • 34