7

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!

BeachRunnerFred
  • 18,070
  • 35
  • 139
  • 238

1 Answers1

4

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

kgutteridge
  • 8,727
  • 1
  • 18
  • 23
  • 1
    thanks, kgutteridge. no, i haven't stored the facebook ID of the user in person.facebookID and I'm struggling to find how to do this. If you get a chance, can you point me in the right direction or update your answer to show this? also, what kind of object is 'person'? also, i see many code snippets that use "me/feed", but when I try that, the facebook dialog box shows a generic error page. should "me/feed" produce the same results as "StringWithFormat:@"%@/feed/",person.facebookID"? Thanks again! – BeachRunnerFred Jan 24 '11 at 00:37
  • Have you made a request to get the users list of friends ahead of this call? – kgutteridge Jan 24 '11 at 00:39
  • 1
    no, would I do that using "requestWithGraphPath:@"me/friends"? – BeachRunnerFred Jan 24 '11 at 00:49
  • -1 For leaving a very poorly explained solution and then not responding – beeeefy Jan 24 '11 at 01:08
  • Sorry, kgutteridge, the down vote wasn't mine. I am, however, confused by your answer and if you'd be willing to make it more thorough, I'd be happy to select it as the chosen answer. 1) what kind of object "person.facebookID" and how do I obtain it? Also, if I use the "requestWithGraphPath" method to post to a user's wall, does that still provide the user with a dialog box so they can view the post before they submit it? Thanks again for your help. – BeachRunnerFred Jan 24 '11 at 01:15
  • thankfully you are more patient!, if you scroll down to the publish section on the fb graph api docs http://developers.facebook.com/docs/reference/api/post/ , you can see how they form a post to a users wall ie http://graph.facebook.com/PROFILE_ID/feed – kgutteridge Jan 24 '11 at 01:58
  • thank you very much! i'm really having a hard time finding the answers i need in the facebook developer docs, for example I don't see target_id anywhere in the post docs. anyhow, your answer helped a bunch! thanks again! – BeachRunnerFred Jan 24 '11 at 02:43
  • This Code not working more. Please provide if new solution is there. – Gaurav Thummar Dec 09 '13 at 11:20