iOS Facebook authorization - ios

Im trying to get authorization to publish stream and get offline access, but I am getting this error.
And it don't show the permissions that I want to get. My code is below:
self.fb = [[Facebook alloc] initWithAppId:#"xxxxxxxxxxxxxxxx"];
NSArray *permissions = [NSArray arrayWithObjects:#"offline_access", #"publish_stream", nil];
[self.fb authorize:permissions delegate:self];
[self.fb dialog:#"oauth" andDelegate:self];
Someone can tell me what I am missing?

It was just delete the line:
[self.fb dialog:#"oauth" andDelegate:self];
and set the line
[self authorizeWithFBAppAuth:YES safariAuth:YES];
to
[self authorizeWithFBAppAuth:YES safariAuth:NO];

Related

IOS FacebookSDK apprequests dialog error

I'm trying to find solution for my problem during two days. And I want to say what I'm sure what I've read all resource where you could give me a links =)
The problem is. I'm using FacebookSDK 3.1 for iOS. And trying to make apprequests dialog... The code is simple
session =[[FBSession alloc]initWithAppID:#"XXXXXXXXXXXX" permissions:nil urlSchemeSuffix:#"xxxxxxxxxxxx" tokenCacheStrategy:nil];
[FBSession setActiveSession:session];
[self ShowSessionState:session.state];
NSLog(#"Acces token data: %#",[session accessToken]);
[session openWithCompletionHandler:^(FBSession *psession, FBSessionState status, NSError *error) {
// NSLog(#"I'm in");
Facebook * facebook = [[Facebook alloc] initWithAppId:#"XXXXXXXXXXXX" urlSchemeSuffix:#"xxxxxxxxx" andDelegate:nil];
[facebook setAccessToken:FBSession.activeSession.accessToken];
[facebook setExpirationDate:FBSession.activeSession.expirationDate];
[facebook dialog:#"apprequests" andDelegate:nil];
}];
And all what I see.. just Frame with error - Api Error Code:110; Api Error Description: invalid user Id; Error message: Missing user cookie (to validate session user).
But the authorization is successful... I have a valid accessToken.. can get my friends or my own FB data.
As I said I've read a lot of resources.... And really the many people have same problem, but I don't found any useful solution for this problem. So help me, please.
I'm found a solution, maybe it will help somebody else. Actually it looks like exorcism but works) So the problem is: If you logged in facebook from safary or Facebook app, webview doesn't save any cookie... so you need make you logging from webview. You can do it with FBConnect package (read more in google). In Facebook.m file you need change code like this:
[self authorizeWithFBAppAuth:YES safariAuth:YES];
to
[self authorizeWithFBAppAuth:NO safariAuth:NO];
In that case when you will use
[facebook authorize:permissions];
The login come always in webview and you can use any dialogs like apprequests etc.
The one more problem)) Login Dialog doesn't appear? It's one more Facebook bug)) To solve this you just need make a delay when call it:
[self performSelector:#selector(showFBLoginDialog) withObject:nil afterDelay:1];
- (void)showFBLoginDialog {
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"offline_access",
#"publish_actions",
#"read_stream",
#"user_photos",
#"email",
#"publish_stream",
#"user_likes",
#"user_about_me", nil];
[facebook authorize:permissions];
}

Not able to post to friends wall with facebook sdk in ios

I have tried with openGraph and normal dialog as below,
[facebook requestWithGraphPath:[NSString stringWithFormat:#"/%#/feed",#"friends_fb_id" ] andParams:variables andHttpMethod:#"POST" andDelegate:self];
and
[facebook dialog:#"feed" andParams:params andDelegate:self]
I gave params for both methods as
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"friends_fb_id", #"to",
#"I'm using the Hackbook for iOS app", #"name",
#"Hackbook for iOS.", #"caption",
#"Check out Hackbook for iOS to learn how you can make your iOS apps social using Facebook Platform.", #"description",
#"http://m.facebook.com/apps/hackbookios/", #"link",
#"http://www.facebookmobileweb.com/hackbook/img/facebook_icon_large.png", #"picture",
nil];
in delegate method it correctly return the Post_id, so its completing successfully but I can not see the post on friends wall. If try using the Hackbook app that comes with SDK it works perfectly.
What could be the possible solution.
Did you forget to enable publish_actions or publish_stream permissions during login?
// login to FB
-(void) FBLogin
{
NSArray *permissions = [[NSArray alloc] initWithObjects:#"publish_actions",#"publish_stream", nil];
[FBSession openActiveSessionWithPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *_session, FBSessionState _status, NSError *_error) {
// do some login handling code here
}];
}
You are using the string "friends_fb_id" should this not be an actual id?
I had a similar situation where is was receiving the correct response, so it was posting, it was just posting to the wrong place.
Make sure the id's are correct.

Facebook scores api with iOS5.1 - Can read scores... but cant post them

I'm new to iOS development, I have successfully integrated facebook login and such... however my problem is with the Score api. i can read the score but i cant seem to post it, i have the publish_actions permission and also am getting back a valid access_token.Not sure what the problem it, here is my code -
NSString *accessTokenToUse = [NSString stringWithFormat:#"%#",[self.facebook accessToken] ];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
//#"233", #"score",
accessTokenToUse, #"access_token",
nil];
NSMutableDictionary *paramsB = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"233", #"score",
accessTokenToUse, #"access_token",
nil];
NSLog(#"APP ACCESS TOKEN: %#",accessTokenToUse);
[self.facebook requestWithGraphPath:#"me/scores" andParams:paramsB andHttpMethod:#"POST" andDelegate:self];
[self.facebook requestWithGraphPath:#"APP_ID/scores" andParams:params andHttpMethod:#"GET" andDelegate:self];
***EDIT - Still doesn't work
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"233", #"score",
#"[APP_ACCESS_TOKEN (omitted for stackoverflow)]", #"access_token", nil];
[self.facebook requestWithGraphPath:#"/[userID]/scores" andParams:params andHttpMethod:#"POST" andDelegate:self];
EDIT - SOLVED
So bascially i WAS passing in the correct token, however the facebook sdk was overwriting it in Facebook.m to the user's access token. So the fix was simple - whenever i need to pass in the App's token i just add an other parameter < key=#"useAppToken" Value=#"yes" > and in Facebook.m just add an if statement within isSessionValid -
- (FBRequest*)openUrl:(NSString *)url
params:(NSMutableDictionary *)params
httpMethod:(NSString *)httpMethod
delegate:(id<FBRequestDelegate>)delegate {
NSLog(#"PARAMS BFORE: %# ", params);
[params setValue:#"json" forKey:#"format"];
[params setValue:kSDK forKey:#"sdk"];
[params setValue:kSDKVersion forKey:#"sdk_version"];
if ([self isSessionValid]) {
if ([params objectForKey:#"useAppToken"] == nil || [params objectForKey:#"useAppToken"] == #"no") {
[params setValue:self.accessToken forKey:#"access_token"];
}
}
NSLog(#"PARAMS AFTER: %# ", params);
[self extendAccessTokenIfNeeded];
FBRequest* _request = [FBRequest getRequestWithParams:params
httpMethod:httpMethod
delegate:delegate
requestURL:url];
[_requests addObject:_request];
[_request addObserver:self forKeyPath:requestFinishedKeyPath options:0 context:finishedContext];
[_request connect];
return _request;
}
Be sure to comment out the NSLogs in this... :)
Scores can only be published using application access_token and not one for user (which you probably using, it's ok for reading the scores but don't allow you to publish 'em).
Citing the Scores documentaion:
Create or update a score for a user
You can post a score or a user by issuing an HTTP POST request to /USER_ID/scores with the app access_token as long as you have the publish_actions permission.
Looks like it's a bug:
http://developers.facebook.com/bugs/461900043821056
But if you change your app settings to web app instead of native it would work.

Post a message on Facebook wall using Graph API

I have used the Graph API, and have successfully logged in to Facebook and gotten the friends list.
Now I need to post a message on the wall. How?
use the url for posting on wall and use this method for post on wall
- (void)postToWall
{
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.userMessagePrompt = #"Enter your message:";
dialog.attachment = [NSString stringWithFormat:#"{\"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\"}}}"];
[dialog show];
}
You can also learn how to publish wall and other essential practice for iOS Facebook Development from the demo that official published by facebook "Hackbook for iOS"
NSMutableDictionary *variables = [NSMutableDictionary dictionaryWithCapacity:1];
[variables setObject:#"this is a test message: postMeFeedButtonPressed" forKey:#"message"];
FbGraphResponse *fb_graph_response = [fbGraph doGraphPost:#"yourFriendFbID/feed" withPostVars:variables];
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *facebook_response = [parser objectWithString:fb_graph_response.htmlResponse error:nil];
[parser release];
if you want to post to your wall thought your FB app without showing a dialog you could do it like this
NSString *message = #"some text";
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:message, #"message",nil];
[fb requestWithGraphPath:#"me/feed" andParams:params andHttpMethod:#"POST" andDelegate:self]; //fb here is the FaceBook instance.
and for sure you will do that after the user login and authorized the permissions .

iOS Facebook cannot post on another user's wall

I am trying to make a post on another user's wall using another user using FBConnect. I am using the embedded method of the iOS Facebook API (that is, I am forcing the browser to appear inside my app, so I am not leaving the application at all). This method works for posting into the wall of the same user, but doesn't work on the wall of another user.
self.facebook = [[[Facebook alloc] initWithAppId:self.appID andDelegate:self] autorelease];
if ([self.facebook isSessionValid]) {
[self proceedToPost];
}else{
NSArray *permissions = [NSArray arrayWithObjects:#"publish_stream", #"email", #"read_stream", #"manage_pages", nil];
[self.facebook authorize:permissions];
}
- (void)proceedToPost
{
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys: #"aName", #"name",
self.appID, #"app_id",
self.title, #"caption",
self.link, #"link",
#"animateURL", #"picture",
nil];
[params setObject:"my-user-profile-id" forKey:#"to"];
[self.facebook dialog:#"feed" andParams:params andDelegate:self];
}
The problem is that authorization is done as expected, but when trying to actually post, I see an error message in the embedded browser "cannot post to user's wall".
Can anyone help me with this?
Did you request the publish_stream permission from the extended permissions?
From the documentation about publish_stream permission:
Enables your app to post content, comments, and likes to a user's
stream and to the streams of the user's friends. With this permission,
you can publish content to a user's feed at any time, without
requiring offline_access. However, please note that Facebook
recommends a user-initiated sharing model.
http://developers.facebook.com/docs/reference/api/permissions/
You can request permissons like this:
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"publish_stream",
nil];
[facebook authorize:permissions];
[permissions release];

Resources