Facebook Graph post image to page - facebook

I can succesfuly upload pictures to my own wall by posting an image to https://graph.facebook.com/me/photos. Now i need to post to a page's wall instead. I have the page ID, but when i change "me" in the url to the pages ID, the image is still posted to my own wall instead of the page's. How do i post an image to a page's stream?
And which permissions is required to do so?
It would be great if you guys could help me out, has got stuck on this one. Thank you!

You cannot upload pictures to wall (it's uploading to album).
To upload picture to Page's Album you need to use page access_token that is accessible via accounts connection of user (you'll need manage_pages permission to get this info).
Once you have access_token for page you may upload picture in the same way as you do for user but using page id instead of user id (you will need publish_stream permission for user to post content pages he own).

m_imgData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForAuxiliaryExecutable:#"Default.png"]];
NSMutableDictionary *fbArguments = [[[NSMutableDictionary alloc] init] autorelease];
[fbArguments setObject:self.m_imgData forKey:#"source"];
[fbArguments setObject:#"Uploading images" forKey:#"message"];
[m_facebook requestWithGraphPath:#"Page_ID/photos"
andParams:fbArguments
andHttpMethod:#"POST"
andDelegate:self];
Where i am using Default.png as a image to upload.
m_facebook is allocated object of Class Facebook (Provided as a part of Facebook SDK).
m_imageData is an object of NSData.

Related

iPhone App Send Facebook Message or Post to Friend's Walls

Here is my current setup. I can click a button and post an image and a comment or news story directly to my wall, mainly just doing some simple FBConnect or ShareKit options.
I would like to expand this to something more complex and engrossing/useful. I would like to be able to take a comment or news story, and either send it in a message to someone on Facebook, or post it to any of my friend's walls.
I believe I will need to use Facebook Open Graph to accomplish this, but am unsure of where to begin. I do have an App setup in Facebook, though it is essentially just for the purpose of SSO with my apps. Could someone direct me to a good tutorial to do what I would like and/or guide me through getting my app set up in Facebook, and then some suggestions for integrating with iPhone?
For posting on Friend's wall, you can use FB's graph api. Here you go with the minimal code snippet for publishing something on friend's wall:
NSMutableDictionary* params = [NSMutableDictionary dictionary];
[params setObject:#"Some text" forKey:#"user_message_prompt"];
[params setObject:#"another text" forKey:#"action_links"];
[params setObject:#"Yet another text" forKey:#"attachment"];
[params setObject:#"SOME FACEBOOK ID" forKey:#"target_id"];
//At some point you need to create the following Facebook instance
[facebook dialog: #"stream.publish" andParams: params andDelegate: self];

how to retrieve photos from Facebook

i have tied lot to get the uploaded images fom the facebok to a UITableviewcontroller,but i get the profile picture only.i have a image cropping application which can get images from library,from camera,fromfacebook.so when the user tap the Facebook button,it will authenticate and if the authentication success,it will strive the photos from Facebook to UITableview.Is that possible if yes how to do this.
I do have this code:
NSString *url = [[NSString alloc] initWithFormat:#"graph.facebook.com/%#/picture",objectId];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]];
But I'm not sure What is objectID and where can i get it?
Please help me.Thanks in advance.
First you have to get album objects.
How to do that is here: fetching facebook albums from an IOS app
Once you have album objects - each of them contains array of photo objetcs (IDs).
Please take a look at deanWombourne's answer at How to get photos of a facebook album in iPhone SDK?.
And from there on your code should work just fine.

FBConnect iOS: Post photo to feed with message every time

I am working on an iOS app that needs to post to either Twitter, or Facebook, or both, every N minutes. The post needs to include a photo and message. I have this woking fine for Twitter, however I'm running into some issues with FBConnect.
The only way I've found to post an image using the image data, rather than a link, is to post to /photos (graph API) and include a message parameter. Unfortunately, it seems that after the first post, subsequent posts either don't show up, or show up as "User added photo to album {app_name}", instead of the message and photo.
Here is my code:
NSMutableDictionary* params = [NSMutableDictionary dictionary];
[params setObject:message forKey:#"message"];
if (image) {
[params setObject:image forKey:#"picture"];
[fb requestWithGraphPath:#"me/photos" andParams:params
andHttpMethod:#"POST"
andDelegate:self];
} else {
[fb requestWithGraphPath:#"me/feed" andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
Is there a way to post an image to the feed directly so that the message and photo show up every time? The only way I could think of was to post a photo to the album and then make a second call to add a feed post with a link to the photo in it, but I'd really rather make just one call.
There's no way to do it directly. Your approach is good.
Even using a second call to add a feed post with a link to the photo from your FB album won't work. You will get a "FBCDN image is not allowed in stream" error.
It seems that you have to upload your picture to a server other than Facebook, and then post a link to that picture to the feed request.
I know it sounds pretty crappy, but I have not found anyway around it yet. I don't understand why Facebook doesn't want to allow wall posts that use a photo in an album as the thumbnail.

Is it possible to post a message on the wall without a dialogue in iphone app using fbconnect?

I'm using facebook connect for my iphone application. I need to be able to post messages on the wall WITHOUT USING PROMPTING DIALOGUES. All i wanna do is enter text into a textfield and then post the text on the wall by clicking a button. Is it possible to implement this?
This is explained in the tutorial here.
https://developers.facebook.com/docs/mobile/ios/build/#socialchannels
If you DON"T want to use dialogs then you need this.
http://developers.facebook.com/docs/reference/iossdk/request/
http://developers.facebook.com/docs/reference/rest/#publishing-methods
Also see this answer: iOS Development: How can I get a Facebook wall post to show in the friend's news feed?
I'm assuming that you have successfully authenticated the facebook and you have a valid object of facebook.
NSString *message = [yourTextField text];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:message, #"message",nil];
[facebook requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];

Photo posted via FB Graph API doesn't appear on the wall (and 2 more FB questions)

I post photo on the wall using Facebook Graph API, just set parameter "picture" and send POST request to "me/photos".
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
self.imageToFBPost, #"picture",
FACEBOOK_ICON_URL, #"icon",
nil];
[facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
Usually (basically always) when I add photos to my PF they appear on my wall. But not in this case. I've tested yesterday about 20 times and only 1-2 times photos appeared on my wall. Basically I want them to appears on my friend's feed. Main question: is there any way to make photo appear on my wall each time she it was posted?
Second question is how to customize icon of the post? E.g. when I of mobile upload under the wall post I see this icon: . I want to see icon of my app instead. I 've set icon of my Facebook app, but it isn't showed anywhere...
3rd question is how to get link to the Facebook page with a photo?
As result of request mentioned above I receive "id" of the picture. I want to open Safari with Facebook page of uploaded picture. Is it possible? I can find only direct link to the .jpg file, but not to the FB page. I've tried to go to http://graph.facebook.com/photo_id but it does't work...
Also it isn't very clear for me ho to catch various responses in the same file. E.g. if I do login, photo posting and requesting photo info in the same class. I created request_id class variable for that and execute switch/case in method comparing request_id with constants, but this way looks "ugly" for me. Any nice solution? :)
Thanks!
1rst question: Facebook decides what to display on your friends feed. displaying one post per photo would be overwhelming so FB chooses to group your images by album into the same post.
2nd question: in your application settings page (https://developers.facebook.com/apps) you can modify the icon displayed for each one of the posts.
3rd question: each requestWithGraphPath methods return a FBRequest instance ref. Keep it somewhere and once your delegate gets called back, compare the passed FBRequest with the ones you kept asside.