FBConnect iOS: Post photo to feed with message every time - iphone

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.

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];

Facebook Graph post image to page

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.

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.

iOS Development: How can I get a Facebook wall post to show in the friend's news feed?

I'm integrating Facebook into my iPhone app and I have the code working to publish a post to the user's wall after they login, but I've noticed that the post doesn't show up in the user's news feed that's seen by the user's friends. Instead, it only shows up on the wall of the user. Here's my code...
- (void)publishStream
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Post a message on your wall", #"user_message_prompt",
#"Hello, World!", #"message",
nil];
[facebook dialog:#"feed"
andParams:params
andDelegate:self];
}
How can I have it show up in the news feed as well? I should mention that the only permission I have set is 'publish_stream' which, as I understand it, is the only permission I need.
Thanks so much for your wisdom!
You need to post to your friends feed, Easy way would be to adapt your code to use the appropriate graph method with the persons you wish to post to facebook ID (i've assumed here you have stored this from an earlier call the graph api in person.facebookID)
[facebook requestWithGraphPath:[NSString stringWithFormat:#"%#/feed/",person.facebookID] andParams:params andHttpMethod:#"POST" andDelegate:self
http://developers.facebook.com/docs/reference/api/post
To get a list of the users friends use the graph path me/friends
[facebook requestWithGraphPath:#"me/friends" andDelegate:self];
Which will return a JSON list of the users friends names and their Facebook ids, to the appropriate delegate method from FBRequest, its probably worth wrapping this set of results into a set of person objects or storing the returned NSDictionary so that you can retrieve individual friends, its upto you how you process the list of returned friends (you probably want to use a UITableView to display the user friends or filter based on some other input from the user)
Using this method will mean you do not have to use the Facebook dialogs in the iOS sdk, which does mean there is an upper limit to how many messages the user can post in a day using your app
If you wish to use a dialog you will need to include the "target_id" in your params dictionary and set this to the persons Facebook ID you wish to post to