I'm new to Android and I'm trying to develop my own APIs regarding facebook.
I have succeeded to some extent but I have a problem in posting data like videos, comments, photos etc. Can anyone please tell me how to write that using HttpPost and OutputStream.
HttpPost mPost=new HttpPos开发者_运维问答t("https://graph.facebook.com/me/feed?access_token="+URLEncoder.encode(access_token)+"&"+"message="+URLEncoder.encode("hii folks"));
HttpClient mClient=new DefaultHttpClient();
HttpResponse mResp=mClient.execute(mPost);
HttpEntity mEnt=mResp.getEntity();
InputStream is=mEnt.getContent();
Log.w("Response post my status message",convertStreamToString(is));
Don't re-invent the wheel: just use RestFB (at http://restfb.com/). It is quite frankly the next best thing to sliced bread as far as Java/Facebook interaction.
This is publishing a photo:
FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
FacebookType publishPhotoResponse = facebookClient.publish("me/photos", FacebookType.class,
getClass().getResourceAsStream("/cat.png"), Parameter.with("message", "Test cat"));
You can do exactly the same thing with me/videos
to publish a video. It will not handle type conversion of the video file for you but I believe Facebook takes care of that.
精彩评论