I want to post some message on Facebook wall.
I am able to log in and connect with Facebook from iPhone. But I have hard luck to finding out the solution.
Can you please tell me how I can achieve this functionality?
Assuming that you have a valid FBSession Object:
FBStreamDialog* dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self; dialog.userMessagePrompt = #"Example prompt";
dialog.attachment = #"{\"name\":\"Facebook Connect for iPhone\"," "\"href
\":\"http://developers.facebook.com/connect.php?tab=iphone\"," "\"caption\":\"Caption
\",\"description\":\"Description\"," "\"media\":[{\"type\":\"image\"," "\"src
\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\"," "\"href
\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}]," "\"properties \":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}"; // replace this with a friend's UID // dialog.targetId = #"999999";
[dialog show];
Source: Facebook Connect Reference
Related
I use the simple FBStreamDialog example in my iPad app:
FBStreamDialog* pDialog = [[[FBStreamDialog alloc] init] autorelease];
pDialog.delegate = self;
pDialog.userMessagePrompt = #"Example prompt";
pDialog.attachment = #"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}";
NSLog(#"prompt: %#", pDialog.userMessagePrompt);
NSLog(#"attachment: %#", pDialog.attachment);
[pDialog show];
NSLogs are OK.
The problem is that neither message prompt nor attachment are shown in FBStreamDialog.
Can anyone help?
The problem was in simulator. It works on device.
I was ussing Facbook connect in my iPhone app, but in december the posts stopped working. After some research I found that i'm supossed to use stream.publish, something like:
NSString *att = #"{\"bob\":\"i\'m happy\",\"caption\": \"User rated the internet 5 stars\", \"description\": \"a giant cat\"}";
NSDictionary *attachment = [NSDictionary dictionaryWithObject:att forKey:#"attachment"];
[[FBRequest requestWithDelegate:self] call:#"facebook.stream.publish" params:attachment];
Which i think it's correct, but the posts still don't work. Someone told me that i need to get publish_stream extended permission from the user, but i dont know how to do that.
Present the FBPermission dialog and ask the user for the extended permission
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] initWithSession:session] autorelease];
dialog.delegate = self;
dialog.permission = #"publish_stream";
[dialog show];
No Matter what i do, i cannot get a post published to an application page wall (the app being logged into) via an iPhone application. I'm able to log in using FBLoginDialog and then retrieve data to populate a tableview, however when i click a button to publish some test content it doesn't work. Here is the button action:
- (void)compose:(id)sender;
{
NSString *tid=#"115372005166292";
NSString *body = #"My Test";
NSArray *obj = [NSArray arrayWithObjects:body,[NSString stringWithFormat:#"%#", tid],nil];
NSArray *keys = [NSArray arrayWithObjects:#"message",#"target_id",nil];
NSDictionary *params = [NSDictionary dictionaryWithObjects:obj forKeys:keys];
[[FBRequest requestWithDelegate:self] call:#"facebook.stream.publish" params:params];
}
I have also used the FBStreamDialog which works, however i'm faced with two issues there. The dialog lacks customization and i'm unable to handle the callback when the item is posted (e.g. reload the tableview)
I've been searching the internet and all of the examples are similar to the code above, so i'm not sure what i could be missing.
Thanks
You need to ask for extended permissions. After login show this:
FBPermissionDialog* dialog = [[[FBPermissionDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.permission = #"status_update";
[dialog show];
Doc: http://github.com/facebook/facebook-iphone-sdk/#readme
I found out how to send some text on the user's wall, with the FBConnect API, on iphone.
I even found how to put an image already on the internet :
FBFeedDialog* dialog = [[[FBFeedDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.templateBundleId = 12345;
dialog.templateData = #"{\"image\":[{\"src\":\"http://sample.png\",\"href\":\"http://sample.com\"}] }";
[dialog show];
(see http://wiki.developers.facebook.com/index.php/Facebook_Connect_for_iPhone)
But I can't figure out how to upload an UIImage from my iphone to the user's wall with FB Api.
Do I have, first, to upload the image on any website, then put its url in the templateData ?
Isn't there any simpler solution ?
Thanks.
Martin
Use the below function to upload the image, pass the UIImage as the parameter, it will work.
- (void)uploadPhoto:(UIImage *)uploadImage
{
NSMutableDictionary *args = [[[NSMutableDictionary alloc] init] autorelease];
[args setObject:uploadImage forKey:#"image"]; // 'images' is an array of 'UIImage' objects
[args setObject:#"4865751097970555873" forKey:#"aid"];// this should be album id
uploadPhotoRequest = [FBRequest requestWithDelegate:self];
[uploadPhotoRequest call:#"photos.upload" params:args];
NSLog(#"uploading image is successful");
}
[[FBRequest requestWithDelegate:self] call:#"facebook.photos.upload" params:params dataParam:(NSData*)img;
and pass params to nil . it will upload image to default album
I want to connect facebook API's with my IPhone. For this I have downloaded the FBConnect sdk and included the FBConnect group of FBConnect.xcodeproj in my application and then I have written the following code in FacebookAPPViewController.m
- (void)viewDidLoad{
[super viewDidLoad];
session = [FBSession sessionForApplication:#"a31c3e53bba4a5f2b3955d6e5e 876717" secret:#"6ecbefa3807406bd13187297e58efae9" delegate:self];
FBLoginButton *button = [[[FBLoginButton alloc] init] autorelease];
[self.view addSubview:button];
FBLoginDialog* dialog = [[[FBLoginDialog alloc] init] autorelease];
[dialog show];
}
but it is showing error that session undeclared. That is right also because I have not initialized it but if I declare it with class `FBSession then also It displays some error and if I exclude this line then the button to connect to facebook does not appear.
Can some one help me?
Thanks in advance
Gaurav
After setting up the session, you should pass it to the login dialog:
FBSession *session = [FBSession
sessionForApplication:#"a31c3e53bba4a5f2b3955d6e5e 876717"
secret:#"6ecbefa3807406bd13187297e58efae9" delegate:self];
FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];
[dialog show];
In your example, you're opening the login dialog right away, so there's no need to add a login button to your view.
PS. I hope you didn't use your real secret key in your code sample...