Post image to album on predefined page

I am trying to allow a user to post an image on my website in an album on a specific facebook page. Before he can select an image on his computer, he must be registered in facebook and must provide the necessary rights to our application (random stream)

To place the selected image in the album of our page, we need an access token, so we have rights for this. We can obtain permissions manually by following these steps:

  • Go to the URL below as the page administrator and grant 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 
  • When you grant the application the required permissions, you will be redirected to canvas_url # access_token = * access_token *, for example

     http://example.com/#access_token=awe12 
  • Then go to

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

    The pages that you control are listed here; write down access_token for the pages on which you want to upload the image.

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

+4
source share
1 answer

You do not need to use the access_token page to publish it to the album. If you use the access_token page, the image will be displayed as if it was sent by the page (and not by the user).

While the album has open access (means that anyone can upload photos to album albums). All you need to do is ask the user to grant you publish_stream permission and upload the image using its access_token.

If you do this with 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 need to enable the imageUpload function in the $facebook object and pass the script signed_request or set access_token so that the current access_token user can use the SDK.

+1
source

Source: https://habr.com/ru/post/1398226/


All Articles