Thursday, November 8, 2012

Facebook Upload Photo using c#

You can either create one album and upload to the album, otherwise you can upload to the default album of your app.
In order to publish a photo to a user’s album, you must have the publish_stream permission. With that granted, you can upload a photo by issuing an HTTP POST request with the photo content and an optional description to one these to Graph API connections:
  • 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.
  • https://graph.facebook.com/ALBUM_ID/photos - The photo will be published to a specific, existing photo album, represented by the ALBUM_ID. 
 Upload to the default album



WebClient client = new WebClient();
client.UploadFile("https://graph.facebook.com/me/photos?access_token=" + accessToken + "&message=" + name, "POST", path);  


upload to the particular album


WebClient client = new WebClient();
client.UploadFile("https://graph.facebook.com/" + albumID + "/photos?access_token=" + accessToken + "&message=" + name, "POST", path);
 

  

4 comments:

  1. Thanks! I was trying to do this using the FacebookMediaObject and kept getting an unauthorized #324 error.

    ReplyDelete
  2. Holy cow i never thought it was so simple. this is the answer that i was looking for in ages. Thanks a lot

    ReplyDelete
  3. when uploading like that, will it show on the user news-feed?

    ReplyDelete
  4. Could you please provide any sample solution?

    ReplyDelete