[SOLVED] Facebook Graph API - upload photo . Anyone done this? (re: my webinar question)

hi,

the Facebook Graph API exposes a function to upload a photo to a user’s album…

you can see PHP examples here
http://forum.developers.facebook.net/viewtopic.php?pid=291678

the Graph API doc for upload is here
http://developers.facebook.com/docs/reference/api/photo/


Publishing

Requires the publish_stream permission.

To publish a photo, issue a POST request with the photo file attachment as multipart/form-data.

You can publish an individual photo to a user profile with a POST to
http://graph.facebook.com/PROFILE_ID/photos

We automatically create an album for your application if it does not
already exist. All photos from your application will be published to the same automatically created album.

You can publish a photo to a specific, existing photo album with a POST to http://graph.facebook.com/ALBUM_ID/photos.

curl -F ‘access_token=…’ <br> -F ‘source=@file.png’ <br> -F ‘message=Caption for the photo’ <br> https://graph.facebook.com/me/photos

here is another example using PHP
[php]
$data = array(
basename($row[‘file_location’]) => “@”.realpath($row[‘file_location’]),
“message” => $row[‘description’],
“uid” => PAGE_ID,
“access_token” => ACCESS_TOKEN
);
$ch = curl_init();
$url = “https://graph.facebook.com/GRAPH_ALBUM_ID/photos”;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$op = curl_exec($ch);
curl_close($ch);
[/php]

thanks for any suggestions
j [import]uid: 6645 topic_id: 5642 reply_id: 305642[/import]

note the @ in the filename is used by Curl to say “urlencode this file as data” basically.

i’m not sure how this would be done in Corona MIME encoding? or what the actual syntax to the graph api call would be [import]uid: 6645 topic_id: 5642 reply_id: 19282[/import]

I too am interested in how to accomplish this. The example shows how to post a photo from a URL but not as multipart form data which is much more useful IMO.

Anyone? [import]uid: 11554 topic_id: 5642 reply_id: 23028[/import]

Also highly interested in this ability… anyone been able to get it to work? [import]uid: 5527 topic_id: 5642 reply_id: 23050[/import]

add your +1 here
http://developer.anscamobile.com/forum/2011/03/23/binary-mime-attachment-facebookrequest

thanks
j [import]uid: 6645 topic_id: 5642 reply_id: 29650[/import]

This functionality has been added as of Daily Build 2011.707.

Here’s a tutorial on how to do it:
http://blog.anscamobile.com/2011/12/uploading-photos-to-facebook-in-corona/

NOTE: The tutorial includes important information regarding build.settings for any iOS app using the Facebook API in build 2011.707 and later, regardless if you intend to upload photos or not. [import]uid: 52430 topic_id: 5642 reply_id: 74244[/import]

great… thanks for the update

j [import]uid: 6645 topic_id: 5642 reply_id: 74901[/import]