1
votes

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?

2

2 Answers

2
votes

The aid is not the ID you should be using when you do the upload. This is not obvious from the Facebook docs - but you should use the object_id column as this represents an object on the Graph API.

So, change your FQL query to:

SELECT object_id,can_upload,created,name,description FROM album WHERE owner={0}

The object_id is just a number - not two numbers separated with an underscore. So make your post to:

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

Note that you only need user_photos permission to upload photos. But without publish_stream permission they do not appear in the user's album straight away - instead, when the user browses to the album they will see this:

enter image description here

Once they click approve they will appear in the album. If your application has publish_stream then they will go straight into the album and the user will not need to approve them.

The rest of your code should be correct.

0
votes

The redirect URI, set to 'https://www.facebook.com/connect/login_success.html', as I'm working on a desktop application

I'm not clear how you are getting USER'S access token in this case. To me it looks like you don't get it but instead you are using your APP'S token - that's why weird album name. Can you double check in Token Debugger that you indeed use user's token?

I have similar workflow for one of my windows forms app - but I do redirect user to localhost - that's where my WCF service is listening and acquiring user's access token from.