I am using Login with Facebook using this
where i can open session with
NSArray *permissions = [NSArray arrayWithObjects:#"email", nil];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
/* handle success + failure in block */
}];
which ask user for permission to read email address of facebook user.
Now i want my application to ask user for "publish_actions" permission together means once user allow to read email address, it will ask for "publish_actions".
how can i do this??
Related
I've created App from https://developers.facebook.com/apps, I'm getting weird error like > FBSDKLog: FBSession: a permission request for publish or manage permissions contains unexpected read permissions
1. My Xcode Bundle ID matches with current Fb App 2. I'm using my App to publish Check Ins to my Friends
I've given permissions to Publish Check Ins are as below code
NSArray *permissions = [[NSArray alloc] initWithObjects:
#"public_profile",
#"basic_info",
#"user_friends",
#"status_update",
#"publish_actions",
#"publish_checkins",
#"user_checkins",
nil];
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error)
Any Help will be appreciated -I'll provide more information if it's needed Thanks..
You will need to separate your request for read permissions from write permissions and request them from the user in that order.
To request read permissions:
[FBSession openActiveSessionWithReadPermissions:#[#"basic_info", #"user_checkin"]
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
To request write permissions:
[[FBSession activeSession] requestNewPublishPermissions:#[#"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
}];
You can read more about the new process in Facebook iOS SDK Upgrade Guide; specifically, read the section, Asking for Read & Write Permissions Separately.
In my project i am not posting anything only fetching different data from FaceBook.
some times i am getting the data but
most of the time i am getting this Error
The operation couldn’t be completed. (com.facebook.sdk error 5.)
my small code is
permissions = [[NSArray alloc] initWithObjects:#"user_friends",#"read_stream",
#"read_requests",#"user_birthday",#"user_about_me",#"user_hometown",
#"user_location",#"user_likes",#"email",
nil];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
NSString *queryNew55 = #"SELECT post_id,fromid,time FROM comment WHERE time > 1375553100 AND post_id IN (SELECT post_id FROM stream WHERE source_id = me())";
// Set up the query parameter
NSDictionary *queryParam15 = #{ #"q": queryNew55 };
// Make the API request that uses FQL
[FBRequestConnection startWithGraphPath:#"/fql"
parameters:queryParam15
HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (error) {
NSLog(#"Error in comment query");
NSLog(#"Error: %#", [error localizedDescription]);
} else {
NSLog(#"comments Result: %#", result);
}
}
];
}];
I seen lots of thing on google on the same Error
and i applied that too but nothings works permanently.
in FaceBook App All the things like sandbox mode is off and bundle id are set perfectly.
any help like link or code or any thing related to this will be great Help.
I know this question is old, but my answer might help some other people.
I was getting this error after following some of their code/tutorials/documentation.
It seems there is a disconnect between their documentation and some of the sample code.
using
if (FBSession.activeSession.state != FBSessionStateCreated) {
// Create a new, logged out session.
self.facebookSession = [[FBSession alloc] init];
}
and
[self.facebookSession openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
will not result in the session being updated in
FBSession.activeSession
getting updated.
So you will have a session that is open (self.facebookSession) and a session that is crated&TokenLoaded - which is not open.
So making any calls like:
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
will fail as the FBRequestConnection uses FBSession.activeSession
So in the completion handler you can see the active session if you are going to manage the session your self.
[self.facebookSession openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
[FBSession setActiveSession:session];
// post or load user data.
}];
It seems to work for me now,
hope this helps
I am beginner of iphone developer. I want to login in my app through facebook. I have using facebook graph API. I have passed the doGraphGet method but its not give email id and password. I am using below code..
-(IBAction)getMeButtonPressed:(id)sender {
FbGraphResponse *fb_graph_response = [fbGraph doGraphGet:#"me" withGetVars:nil];
NSLog(#"getMeButtonPressed: %#", fb_graph_response.htmlResponse);
}
It returns the response of
id, firstname, lastname, name, link, username , gender but it is not giving email id and password
so, give any suggestion and source code which is apply in my code..
For that, first you need to ask user permission, and setting different permission for Facebook Api.
Have a look at below permission:
arrFBPermission = [[NSArray arrayWithObjects:
#"email",
#"user_birthday",
#"user_likes",
#"user_location",
#"user_photos",
#"read_stream",
#"status_update",
#"user_about_me",
#"read_friendlists",
#"friends_about_me",
#"friends_birthday",
#"friends_photos",
nil] retain];
Then, as per the latest facebook SDK, you can use the login method as below:
[FBSession openActiveSessionWithReadPermissions:arrFBPermission
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
After successful login, below delegate method will be called:
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
}
And facebook api will not provide you Password.
Hope, you will get success.
Happy Coding!
Cheers!
While using auto-login from native facebook, if I get logged out from native app then session won't work and facebook default login page get displayed. How could I detect that after which delegate or function of FBSession class is called after which the facebook default login page get displayed and restrict it to get displayed?
This is what I am doing to do a auto login
CacheToken = [[FBTokenCache alloc]init];
NSArray *permissions = [[NSArray alloc]initWithObjects:#"email,user_photos,user_videos,publish_stream,offline_access,user_checkins,friends_checkins", nil];
self.fbsession = [[FBSession alloc] initWithAppID:#"484473011575776"
permissions:permissions
urlSchemeSuffix:nil
tokenCacheStrategy:CacheToken];
(fbsession is the object of Facebook SDK class FBSession)
[FBSession setActiveSession:self.fbsession];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
You can user facebook old sdk. In facebook.m just allow your app to open within app i.e trySafari = FALSE; and tryFBApp = FALSE;
I am using this.
Hope this will also help you.
I have quick question:
this code snippet works:
NSArray *permissions = #[#"email", #"user_birthday"];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
And this doesn't:
NSArray *permissions = #[#"email", #"user_birthday", #"gender"];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
I'm simply asking for the gender of the Facebook user and in first case I've got on my NSLog console: User session found which is great... but when I extend the permission and include gender in it, I've got UIAlertView with:
Error
The operation couldn't be completed. (com.facebook.sdk error 2.)
What I am doing wrong? How to ask for permission to get user gender?
As you can see here, the gender is part of the basic informations.
And whenever you open a session with permissions, it will ask for basic informations.
Since you already have it, facebook musts consider it as an error.
I had the same issue when asking for the username by the way.
Gender is not a public property of , so, you can't access using user.gender, as you do with user.name, here you have a dictionary and you access passing the Key.
like:
_genderLabel.text = [user objectForKey:#"gender"];
Cheers
Look at the list of permissions - gender is not one of them - gender is, however a field of the User object and is also exposed in the sex column in the user FQL table which you can access once the user has granted you the basic permission to access their data.
A sample query (SDK agnostic) to return just the current user's gender is simply
/me?fields=gender, the return value of which will be
{
"gender": "male",
"id": "533875325"
}
Note that it's also returned in the default response when accessing a user, so you don't need to specify it explicitly.
Also, some users may not have a gender defined (though i think this is relatively rare)