1

Possible Duplicate:
Upload photo to users profile from photo URL, not input file field

I have the access_token. It's with the publish_stream permission.

Alright, now I want to upload an image to my default app's album on Facebook. The image is hosted on my S3.amazon.com. (but for example purposes, let's take this link: https://i.stack.imgur.com/DvlWa.jpg)

How can I upload this imgur image to my app's album? (documentation on Facebook is weird, and I don't understand PHP).

TIMEX
  • 259,804
  • 351
  • 777
  • 1,080

3 Answers3

2

To upload photo to "Application Album" you have two ways (actually first may interest you more).

Option 1: Uploading Photos to the Graph API via a URL:

App developers who host their images on Amazon S3 or a similar service can pass the S3 URL directly to Facebook without having to download the file to their application servers only to upload it again to Facebook. This improves performance and reduces costs for developers.

To achieve this you need to issue POST request (or GET with argument method=post) to next URL:

https://graph.facebook.com/me/photos?
       access_token=...&url=http%3A%2F%2Fi.imgur.com%2FPtyzk.jpg

http://i.imgur.com/Ptyzk.jpg in url encoded form is http%3A%2F%2Fi.imgur.com%2FPtyzk.jpg (you only need to encode url if you passing it withing URL arguments, and must not encode if you passing it with post-data).

As stated in photo object documentation, by posting photo to https://graph.facebook.com/USER_ID/photos:

The photo will be published to an album created for your app. We automatically create an album for your app if it does not already exist. All photos uploaded this way will then be added to this same album.

Option 2: Uploading image data

You just need to issue POST request to http://graph.facebook.com/me/photos (see Create Photos section of user object documentation).

The only required parameter is source which is multipart/form-data encoded file, you can either download it to temporary file and upload it later, or stream it to the Graph API (depending on technology you use to implement this functionality)

There is couple of samples how to upload photo (in languages other than PHP):

Update: It's not really clear where do you want photo to be published User's album or Application album (title and body of question are opposite on this). If you want to publish it to User's album you need to replace me with id of album you want photo be uploaded to. Otherwise use me (for current user) or other user id (this will require usage of application access_token).

Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
  • This is spot on! Option 1 is what I was looking for. And you wrote a perfect answer, thank you! I wish I could give you the bounty, but the question's closed. how do I give you the bounty? If you re-open this, I can give you the bounty – TIMEX Feb 01 '12 at 11:11
  • @TIMEX, if this question will be reopened or it's answers merged with other question you can [do it manually](http://meta.stackexchange.com/questions/69592/is-it-possible-to-award-a-bounty-to-or-otherwise-reward-an-exceptional-answer) if you wish ;) – Juicy Scripter Feb 01 '12 at 12:40
1

This tutorial does exactly that:

https://developers.facebook.com/blog/post/498/

You can choose which album you want to upload the picture to.

If you want to do it on a more generic way, Facebook API tells you to issue a POST request to ALBUM_ID/photos with source and message parameters. Note that source must be of multipart/form-data type.

More details at https://developers.facebook.com/docs/reference/api/album/

Marcelo Diniz
  • 2,493
  • 2
  • 21
  • 27
0

I think the majority of this answers are correct if you would like to upload that photo to a user of your app. But as I understand you want to upload it to your app's connected album. To do that you should get you app album's id than you'll be able to post an image to it like:

$facebook->api('album_id', 'POST', array(...

To get the id of the album go to the Graph API explorer and do a GET to: /your_app_id/albums (replace your_app_id with your actual app id). That should give you all the details about your app albums. Than do a Graph API POST request using your preferred SDK (JS, PHP etc.) with the array containing the picture source and a title (this are mandatory) to the above address.

NOTICE: The album application connection is deprecated and will be removed on March 1st, 2012. Read more at the end of this doc http://developers.facebook.com/docs/reference/api/application/

Alexandru Savin
  • 636
  • 5
  • 11
  • Actually posting image to `/me/photos` will add em to Application Album (creating it if album not yet exists) – Juicy Scripter Jan 31 '12 at 11:47
  • @juicy Can you give me a link stating this because I really think you're wrong. /me/photos is the path for the currently loged in user. I can give a reference: [link](http://developers.facebook.com/docs/reference/api/) read this: "Additionally, there is a special identifier me which refers to the current user. So the URL https://graph.facebook.com/me returns the active user's profile." – Alexandru Savin Jan 31 '12 at 12:17
  • voila, [`photo` object documentation](http://developers.facebook.com/docs/reference/api/photo/) – Juicy Scripter Jan 31 '12 at 12:30
  • Same statement you can find in [How-To: Use the Graph API to Upload Photos to a user’s profile](https://developers.facebook.com/blog/post/498/) developers blog post which is referenced here in answers. Added that to my answer for clarification. BTW, Sure you need to replace `me` with `id` of user you want for posting photo to profile other than current user (you should use application `access_token` for that). – Juicy Scripter Jan 31 '12 at 12:35
  • I'd advice you to read again the question : "How can I upload this imgur image to my app's album?" – Alexandru Savin Jan 31 '12 at 13:10
  • App's album is not the same with user album ... – Alexandru Savin Jan 31 '12 at 13:10
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/7197/discussion-between-juicy-scripter-and-alexandru-savin) – Juicy Scripter Jan 31 '12 at 13:17