Home Facebook Graph API: Uploading Photo to specific album
Reply: 0

Facebook Graph API: Uploading Photo to specific album

user3411
1#
user3411 Published in April 25, 2018, 8:41 am

I'm trying to upload photos to a specific album of the authenticated Facebook user. But the photo does not appear in the album. It appears in a new album named '"appname" Photos'. I'll try to describe my way as complete as possible - maybe this helps you out there to find my mistake.

I'm not using any Facebook or third party SDK. The project programming language is C# (if it matters).

First of course, I'm getting an access token, by sending the user to the following URL:

https://www.facebook.com/dialog/oauth?client_id={0}&redirect_uri={1}&response_type={2}&scope={3}
  • {0}: The client ID: my application ID, as provided by Facebook
  • {1}: The redirect URI, set to 'https://www.facebook.com/connect/login_success.html', as I'm working on a desktop application
  • {2}: The response type: 'token'
  • {3}: The scope - all the privileges I'm requesting. This is a comma separated list of the following items:
    • manage_pages
    • email
    • user_about_me
    • user_photos
    • user_videos
    • publish_actions
    • publish_stream
    • user_likes
    • user_activities
    • user_groups
    • photo_upload
    • video_upload

The list of privileges is not only meant for the photo upload.

The login and it's implementation works quite well, so that I get an 'access_token' and an 'expires_in' field in the answer.

If I don't have it already saved, I'm getting the user ID of the authenticated user represented by the access token. This is done by a simple request to:

https://graph.facebook.com/me?access_token={0}
  • {0} is the acquired access token

This also works quite well and I get a positive response with name, e-mail etc. and the user ID.

Next Task, get the list of albums the user associated with the acquired access token and the user ID. This is done by a FQL query:

SELECT aid,can_upload,created,name,description FROM album WHERE owner={0}
  • {0} is the user ID

The FQL query is executed by calling this URL:

https://graph.facebook.com/fql?q={0}&access_token={1}
  • {0} the query from above
  • {1} the access token

Again, this works quite fine - I get the requested fields back. The 'aid' values are used as album IDs later and are in the format 99999999_999999999 (numbers with an underscore somewhere in the middle). I only use albums that have the can_upload flag on "true".

Now, I hope I have all the information I need to publish the photos.

I create a POST request, multipart/form-data, to this URL:

https://graph.facebook.com/{0}/photos?access_token={1}
  • {0} is the 9999999_999999 album ID
  • {1} is the access token from the login

The request consists of two fields: 'source' contains the photo's binary data, 'message' the caption.

The request succeeds. No problem detectable for me.

But when I now visit the Facebook user page, the photos are not in the selected album, they are in an extra album named '"appname" Photos'. The caption is set correctly.

What must I change to bring the photos directly to the desired albums?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.369009 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO