Posting picture on Facebook 'feed' from an

2019-05-13 12:21发布

I am using ASIHTTPRequest to work on Facebook graph API.

This is the nearest I have gone to posting a picture on the feed. So if I have a

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];

The url is https://graph.facebook.com/me/feed

Now to post a picture I do the following:

[request setPostValue:@"My Message" forKey:@"message"];

[request setPostValue:@"somepic.png" forKey:@"picture"];

[request setPostValue:@"Some Name" forKey:@"name"];

[request setPostValue:@"Some description" forKey:@"description];

[request startAsynchronous];

If you try this then everything works fine other than the picture being posted. A blank placeholder for the picture is though show on the feed.

3条回答
欢心
2楼-- · 2019-05-13 12:44

Just use this small snippet to upload a image on your disk as raw data

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setData:UIImageJPEGRepresentation(img.image, 0.1) withFileName:filename andContentType:@"image/jpeg" forKey:@"photo"];
查看更多
做个烂人
3楼-- · 2019-05-13 12:45

I found out this documentation on facebook: http://developers.facebook.com/docs/reference/api/post

According to this documentation we can not post an image residing on our machine using the api. Instead we have to upload the pic and then provide the link for posting to the feed.

But uploading an image on to the wall is allowed if you logon to facebook.com. I believe this functionality is not provided in the graph api.

查看更多
ら.Afraid
4楼-- · 2019-05-13 12:51

It might be worth taking a look at ShareKit - http://www.getsharekit.com/

Their demo app publishes a photo on the Facebook wall successfully. I believe they wrap the upload-then-publish process in their code.

HTH, Oded

查看更多
登录 后发表回答