0

i am working with an iphone app. its a nav based app. in every DetailVew there is a button for publishing some information on user's facebook wall. It ll be link and some information. how can i do that? in developer.facebook.com they have explained steps to do that but in those steos they need facebook app id. i dont have any app against my iphone app on facebook. is it possible to just publish story on facebook wall without having a facebook app? thanx

Piscean
  • 3,069
  • 12
  • 47
  • 96

1 Answers1

2

Yes, it's possible. You'll still need to create a Facebook app if you want to output a story in a custom format but if you just want to output a headline and story, with maybe a link or a picture, there's no need. The code I use looks something like this:

SBJSON *jsonWriter = [[SBJSON new] autorelease];

NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                            [name stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""], @"name",
                            [description stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""], @"description",
                            [url stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""], @"href", nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                               @"XXX", @"api_key",
                               @"Share on Facebook",  @"user_message_prompt",
                               attachmentStr, @"attachment",
                               nil];

[facebook dialog:@"stream.publish" andParams:params andDelegate:self];

This is using the newer Facebook iOS API rather than the older FacebookConnect API.

Stephen Darlington
  • 51,577
  • 12
  • 107
  • 152
  • My facebook button is in DetailView. should i write that code in the method which ll be called when the button is pressed? – Piscean Feb 28 '11 at 15:05
  • Exactly. It will pop up a dialog, allowing the user to click "Post." It assumes that you've already logged into Facebook. – Stephen Darlington Feb 28 '11 at 15:13
  • and its giving error facebook undeclared. last line of ur code. – Piscean Feb 28 '11 at 15:41
  • Have you read the documentation? (https://github.com/facebook/facebook-ios-sdk) That one page tells you how to log in, the data type of `facebook`, how to install the API, etc. – Stephen Darlington Feb 28 '11 at 16:09
  • in that documentation they are asking for app ID which will be facebook app ID. i dont have any app on facebook what should i write here Facebook* facebook = [[Facebook alloc] initWithAppId:appId]; – Piscean Mar 01 '11 at 10:08
  • Let's clarify terminology. When I say you don't need a "Facebook App," I mean you don't need to create a canvas page or a web site or deal in FBML. You do, however, need to create an application in order to get an App ID. You create one on the Facebook developer site. You tell them that it's a "desktop app." – Stephen Darlington Mar 01 '11 at 10:18
  • I read documentation and did what they said. and it went fine. but i have a question now. everything they told is modifying AppDelegate.m, and i used the code u wrote above in DetailViewController.m and its giving 2 errors facebook undeclared. should i write all that code in DetailViewController.m which i wrote in AppDelegate – Piscean Mar 01 '11 at 10:43
  • Yes, you can't (directly) access variables in the app delegate from your view controller. This is pretty basic stuff. You should probably be reading some iOS/Objective-C tutorials before tackling an integration exercise like this. – Stephen Darlington Mar 01 '11 at 11:58