I am developing an app in which I want to share an image on Facebook. I have searched a lot and all the results i could find were using the Facebook android-sdk. But i am not using Facebook android-sdk, so can anyone please help me with the Post request that i am to use along with the parameters to the graph api for uploading photo on my feed??
The image does not have a link, I am uploading it through my mobile.
In this documentation in the publishing section, I am not able to understand the method /ALBUM_ID/photos and its arguments. Please help.
-Thanks in advance
Asked
Active
Viewed 1,132 times
0

Antrromet
- 15,294
- 10
- 60
- 75
2 Answers
0
The URL which you have provided is about Graph Api.
and If you want to use Graph Api, You must have an Access Token, and to get Access Token you are going to use Facebook-Android-SDK.
Remember all the methods in Graph-api needs a valid access token agains your app.

Adil Soomro
- 37,609
- 9
- 103
- 153
-
Not necessarily...I am getting the access token from my server side. I have an access token with me – Antrromet Mar 08 '12 at 09:51
-
ok, then simply you will append that access token and upload image at the url (https://graph.facebook.com/ALBUM_ID/photos?) – Adil Soomro Mar 08 '12 at 10:19
-
Could you please read the question properly. My question is how to upload photos, its the same thing. I dont know how to upload, its exactly my problem. – Antrromet Mar 08 '12 at 10:24
-
I think [this post](http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/) is going to help you to upload image and multipart data, you can also have a look at [this post](http://stackoverflow.com/questions/2935946/sending-images-using-http-post), you will only change the URL and append the AccessToken with it :) – Adil Soomro Mar 08 '12 at 10:27
-
Btw i already checked the link that you gave me earlier, I used it to send images to my server. But no, it didnt work. I tried attaching the access token after the query as 'https://graph.facebook.com/me/feed?access_token=token' and it didnt work, also i tried sending the token as a parameter in the POST request and still it didnt work. – Antrromet Mar 09 '12 at 04:20
-
Try with a URL like this, https://graph.facebook.com/me/photos?access_token=token. I think it should work. – Adil Soomro Mar 09 '12 at 06:37
-
1It worked for me, thank you for your response. I am posting the code below for reference. – Antrromet Apr 03 '12 at 06:53
0
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(
"https://graph.facebook.com/me/photos?access_token="
+ AccessTokens.fbaccesstoken);
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, bos);
byte[] data = bos.toByteArray();
entity.addPart("source", new ByteArrayBody(data, "myImage.jpg"));
entity.addPart("message", new StringBody(caption.getText()
.toString()));
httpPost.setEntity(entity);
HttpResponse response = httpClient.execute(httpPost,
localContext);

Antrromet
- 15,294
- 10
- 60
- 75
-
I used entity.addPart("source", new ByteArrayBody(data, "url of the image")); and I got the following exception. Could not find class 'org.apache.http.entity.mime.MultipartEntity', referenced from method com.fb.friends.FBFriends$Task_Import.doInBackground. Could you help me to resolve this. – Manikandan Jun 06 '12 at 11:36
-
Android SDK uses apache http Client of version 3.0. That does not support for the mime type. You can download the latest HttpClient from this link : http://hc.apache.org/downloads.cgi – Antrromet Jun 07 '12 at 07:38
-
@Manikandan Go to latest i.e. HttpClient 4.1-Beta1, and download zip file from Binary with dependencies – Antrromet Jun 07 '12 at 07:38
-
thanks it works in Android 2.1 onwards. I had tried in 1.6. That is why I got that error. – Manikandan Jun 07 '12 at 14:13