4

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?

ThoDho
  • 65
  • 1
  • 4
  • Hello. Supposedly if you have the offline_access permission then it means you can request access tokens on behalf of the user anytime you want. There is no access-token without an expiration date, but you can always (after the first permission is granted) request your own access-tokens and then do all the process automagically. – gvillavizar Apr 06 '12 at 04:41

1 Answers1

1

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.

Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
Yaron U.
  • 7,681
  • 3
  • 31
  • 45