Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:28:26+00:00 2026-06-08T10:28:26+00:00

So here is what I’m trying to do. I’m trying to use the facebook

  • 0

So here is what I’m trying to do. I’m trying to use the facebook batch api to post a single photo to multiple facebook pages at the same time. I first put everything into an array (fb_batch) then encode it using JSON. This method works just fine for posting messages and links. In the example below the @pages array is an array of facebook pages that contains the facebook page information including a valid access token. I know the access token is valid because elsewhere in the program I can post an individual photo using this same access token.

fb_batch = []
top_access_token = nil
@pages.each do |page|
  top_access_token = page.access_token if top_access_token.nil?
  if image.nil?
    fb_batch << {method: 'POST', relative_url: 'me/feed?access_token=' + page.access_token, body: body}
  else
    fb_batch << {method: 'POST', relative_url: 'me/photos?access_token=' + page.access_token, body: body, attached_files: 'file1'}
  end
end

c = Curl::Easy.new('https://graph.facebook.com')
c.multipart_form_post = true
c.verbose = true
post_data = [Curl::PostField.content('access_token', top_access_token), Curl::PostField.content('batch', fb_batch.to_json)]
post_data << Curl::PostField.file('file1', image.image.current_path) if !image.nil?
c.http_post(post_data)

Notice how I only add the file if there is an image. So this same code works for when I’m posting messages or links to multiple accounts.

The error comes when I post an image to multiple accounts. It will apply the image to the first account an the fb_batch array, but all the other accounts have an error. Do I have to attach the image separately for each account I wish to post the photo to each image having a different attached_file name? To me this means that the request would be huge since I would potentially have to attach the same image 50 times if I was posting to 50 accounts.

Here is the response I get from facebook:

[{“code”:200,”headers”:[{“name”:”Access-Control-Allow-Origin”,”value”:”*”},{“name”:”Cache-Control”,”value”:”private, no-cache, no-store, must-revalidate”},{“name”:”Connection”,”value”:”close”},{“name”:”Content-Type”,”value”:”text/javascript; charset=UTF-8″},{“name”:”Expires”,”value”:”Sat, 01 Jan 2000 00:00:00 GMT”},{“name”:”Pragma”,”value”:”no-cache”}],”body”:”{\”id\”:\”416193168426655\”,\”post_id\”:\”159594100753231_416193185093320\”}”},{“code”:400,”headers”:[{“name”:”Access-Control-Allow-Origin”,”value”:”*”},{“name”:”Cache-Control”,”value”:”no-store”},{“name”:”Connection”,”value”:”close”},{“name”:”Content-Type”,”value”:”text/javascript; charset=UTF-8″},{“name”:”Expires”,”value”:”Sat, 01 Jan 2000 00:00:00 GMT”},{“name”:”Pragma”,”value”:”no-cache”},{“name”:”WWW-Authenticate”,”value”:”OAuth \”Facebook Platform\” \”invalid_request\” \”(#1) An unknown error occurred\””}],”body”:”{\”error\”:{\”message\”:\”(#1) An unknown error occurred\”,\”type\”:\”OAuthException\”,\”code\”:1}}”}]

Sorry it is messy. You can see that the first code is 200 which posts the image successfully and returns the image ID. The second code is a 400 saying An unknown error occurred. I assume this means that it couldn’t find the image or something of that sort. If I switch the two accounts around in the array then it will post successfully to the other account and will fail on the account that just succeeded.

Thanks for reading all the way to the end! Here is your pot of gold…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:28:28+00:00Added an answer on June 8, 2026 at 10:28 am

    My answer somewhat skates around debugging your problem and offers a possible alternative. Back last year, Facebook launched the ability to upload photos by supplying a source URL instead of having to supply multipart data. Therefore, I recommend the following workaround:

    1. Upload the image you want to use to somewhere outside of the Facebook CDN (there can be issues using CDN media to upload to Facebook)
    2. Grab the URL of said image
    3. Instead of making the call you are currently, simplify it to PAGEID/photos?access_token=PAGETOKEN&url=URLOFPHOTO

    This will post the photo directly to the Page’s Timeline. Batching that call should not make any difference. Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Here is the code in a function I'm trying to revise. This example works
Here is what I am currently doing. PHP echo's out the recent post in
Here is my problem : I have a post controller with the action create.
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here is the problem that I am trying to solve. I have two folders
Here is my code (Say we have a single button on the page that
Here's the flow that I am trying to achieve: 1) User uploads an audio
Here is what I am trying to achieve in PHP: I have this string:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.