Post image to an album on a predefined page

I'm trying to let a user post an image on my website to an album on a specific facebook-page. Before he's able to select an image on his computer he needs to be logged in at facebook and must have given the needed rights to our application (casual flow)

For posting the selected image to the album of our page we need an access token so we have the right permissions to do this. We can get the permissions by hand by doing the following steps:

  1. Navigate to the url below logged in as the admin of the page, and give the permissions (user_photos,manage_pages,offline_access,publish_stream)

    https://www.facebook.com/dialog/oauth?
    client_id=<application_id>
    &redirect_uri=<canvas_url>
    &response_type=token
    &scope=user_photos,manage_pages,offline_access,publish_stream
    
  2. When you give the application the required permissions you'll be redirected to canvas_url#access_token=*access_token*, for example

    http://example.com/#access_token=awe12
    
  3. Then navigate to

    https://graph.facebook.com/me/accounts?access_token=#access_token
    (using the access token from 2). 
    

    This will list the pages you administer; write down the access_token for the page(s) to which you want to upload the image

Now, is there a way to do this automagically? Or better, is there a way to generate an access-token for this page, that will never expire?

Answers


You don't have to use the page's access_token in order to post to the page album. If you use the page's access_token then the image will be shown as if it was sent by the page (and not by the user).

As long as the album has public access (means that anyone can upload photos to the page's albums) . All you need is to ask the user to grant you publish_stream permission and upload the image with his access_token.

If you're doing it with the PHP Sdk it should look something like this:

  $facebook->api("ALBUM_ID/photos","POST",array(
        "message"=>"some message",
        "source"=>"@PATH_TO_IMAGE"
  ));

Of course you will need to enable imageUpload in the $facebook object, and pass the script the signed_request or set the access_token in order for the SDK to use the current user's access_token.


Need Your Help

Move inline Google Analytics onclick event to a function

onclick analytics

I have some HTML links which I can't easily modify, but I need to put some tracking code in. An example of the code is: