I m developing an iPhone app which includes facebook wall posting.After log in, I post to user's wall by following code:
NSString *appIcon = [NSString stringWithString:@"http://a2.twimg.com/profile_images/416166235/apple-black_normal.png"];
NSString *appSiteUrl = [NSString stringWithString:@"http://www.apple.com"];
NSString *attachment= [NSString stringWithFormat:@"{\"caption\":\"%@ Likes in the iPhone App\",\"description\":\"\",\"media\":[{\"type\":\"image\",\"src\":\"%@\",\"href\":\"%@\"}]}",_facebookName,appIcon,appSiteUrl];
// [attachment stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSArray *obj = [NSArray arrayWithObjects:attachment,nil];
NSArray *keys = [NSArray arrayWithObjects:@"attachment",nil];
NSDictionary *params = [NSDictionary dictionaryWithObjects:obj forKeys:keys];
NSLog(@"atachment : %@",[params description]);
[[FBRequest requestWithDelegate:self] call:@"facebook.stream.publish" params:params];
This results into Error,saying that "The user hasn't authorized the application to perform this action".
In the Facebook Profile of user, the app has only permission to access user's basic information. So I need to take "stream_publish " from the user.
So how to give extended permission Dialog (for permission of "stream_publish") ??
Any help would be appreciated.
I have Found the solution of the problem by myself.
Actually the cause of the problem is the application doest have permission to "Post To Wall".
(publish_stream).Hence FB was denying with following error.
"The user hasn't authorize this application to perform this action".
So when user logs in, Ask user to give permission of publish_stream,
- (void)session:(FBSession*)session didLogin:(FBUID)uid {
FBPermissionDialog *permissions = [[FBPermissionDialog alloc]initWithSession:_session];
permissions.permission = [NSString stringWithString: @"publish_stream"];
[permissions show];
}
`
When once the user have allowed "Post to wall", this dialog wont appear ever again.
you should have a small block of code that looks similar to this below. If not - search for read_stream in your code -
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
_permissions = [[NSArray arrayWithObjects:
@"read_stream", @"offline_access",nil] retain];
}
Add @"stream_publish" to the list and you should be good to go.
-Jon
The solution above uses FBPermissionDialog which is fine for changing the permissions after login, but you're better off just asking for the permission on the initial login. That way you are not opening up the external browser twice.
if (![facebook isSessionValid]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"publish_stream",
nil];
[facebook authorize:permissions];
[permissions release];
}