I am getting a facebook sdk error on ios when I try to login -- note that I just upgraded the version of my facebook sdk to version 3.21.1. The interesting thing is that it works fine on the simulator. When I log into facebook on my iphone under settings => facebook the facebook login on my app fails, but when I disconnect the native facebook login it works fine again.
Here is my code:
NSArray * basicPermissions = #[#"public_profile", #"user_friends", #"email"];
[FBSession openActiveSessionWithReadPermissions:basicPermissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[DCTLogger debug:#"facebookLoginQ:Callback: %#/%p sess=%# ", [DCTBase stringForFBSessionState:status], error, session];
if (error) {
dispatch_async(q, ^{
handlerCopy(nil, error);
});
return;
}
if (status == FBSessionStateOpen) {
[FBSession setActiveSession:session];
[self facebookSessionCreatedQ:q Callback:handlerCopy];
}
}];
The error I get is com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginCancelled with facebook sdk error code 2.
Another interesting point is that if I remove public_profile from basicPermissions the login works fine, and as per another post I saw about this, if I use the deprecated method of openActiveSessionWithPermissions as opposed to openActiveSessionWithReadPermissions it works fine as well.
Just want to point out again that it only seems to fail when there is a natively logged in facebook account on the device. I have a feeling that perhaps the new sdk automatically includes public_profile so if I request it again in basicPermissions it causes an issue.
Related
I'm using the latest FB SDK via Pods - version 3.18.2, with Xcode 5 in and iPhone only app. I use the FBLoginView in the Storyboard, so tapping it pops open the Facebook login for the app, and login actions call the delegate of the parent View controller of that FBLoginView button.
It all works fine -- but, sometimes the Desktop version of the login shows up rather than the Mobile version. It's intermittent -- I have tester where it never shows, one who gets it sometimes, and one who gets it often.
Any idea how I can prevent the SDK from showing the Desktop login?
If the user doesn't have the Facebook native app installed the facebook website will open.
Otherwise it will open the Facebook native app.
There is a function called openWithBehavior in the Facebook SDK that works on sessions. Use that like I have shown below:
FBSession *session = [[FBSession alloc] initWithPermissions:#[#"public_profile", #"email",#"user_location",#"user_birthday",#"user_likes"]];
[FBSession setActiveSession:session];
[session openWithBehavior:FBSessionLoginBehaviorForcingWebView
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if (FBSession.activeSession.isOpen) {
//Do Something
}
}
]
I just started using facebook sdk and slightly confused with it documentation. It's well written, but very often does not correspond to current SDK version. So i'm not found what to do with this situation:
I request publish permissions when firstly require them, with the next code:
[[FBSession activeSession] requestNewPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
if (error) {
NSLog(#"Permissions request error: %#", error.description);
}
completion(error == nil);
}];
I need only one publish permission - 'publish_actions', when i request it sdk redirects me to facebook app and immediately returns back to the my app without asking whether i'm agree to give this permission.
There are no errors in completionHandler, but through debug i found that this permission was saved in the variable _requestedReauthPermissions:
So, finally, permission i requested not granted to me.
How properly request publish permission? What could I miss? May it occur due to setup of facebook app?
I am using the following code to present the user with the Facebook Embedded WebView Dialog in an iOS 7 app
FBSession *session = [[FBSession alloc] initWithPermissions:#[#"basic_info", #"email"]];
[FBSession setActiveSession:session];
[session openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self sessionStateChanged:session state:status error:error];
}];
On my development iPad, I see the Facebook dialog and login view just fine. On iPhone, the dialog fills the screen just fine, but the spinning progress indicator just sits there forever. Our QA team is seeing the never ending spinning progress indicator on both devices.
Has anyone else seen this behavior? I am about to give up and just implement the Mobile Safari Login Dialog.
I use
FBSessionLoginBehaviorWithFallbackToWebView
and it works for me.
EDIT: You may also want to check to make sure you have the Advanced setting "Embedded Browser OAuth Login" turned on for you Facebook app.
I've created Facebook app using Facebook login flow from the developer page step by step. Login works great. My problem is that this is not working on iPhone 5 or 5s.
I have tried to check on 6 different iPhones 5 and it works only on one of them. Once I've clicked on "login" I get alert with the message the app would like to access to you basic info I get the user cancel login error once I click on "ok" or "don't allow" in the alert. and nothing happens. any idea what could be the problem? thank you
Instead of using FBLoginView, try using FBSession like this:
// no action can be done on facebook if there is no session on open state
if (!FBSession.activeSession.isOpen) {
FBSession *session = [[FBSession alloc] initWithPermissions:#[#"email", #"user_birthday"]];
[FBSession setActiveSession:session];
// Here this behavior garantees that the iOS Login Dialog is not shown, because it was causing some login issues
// The fallback flow will be: 1- Facebook App Native Login Dialog; 2- Facebook App Web Login Dialog; 3- Mobile Safari Login Dialog
[[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorWithNoFallbackToWebView
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
if(error) { // your code here }
else { // your code here }
}}];
Okay, when I try to open new session with publish permissions and pass array of permissions, facebook sdk pops up me an error. com.facebook.sdk code 2 error (which has a lot of explanations and I'm pretty sure that I tried almost everything from here).
That looks something like this:
permissions = [NSArray arrayWithObjects:#"publish_actions", #"publish_stream", nil];
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
if I say: permissions = nil; And call this same thing, everything works okay. After that, I am able to call same function WITH permissions and user is able to post directly on facebook (directly on wall). Am I missing something?
I'm working with latest facebook sdk (3.8 I think) and testing on device with 6.1.4 version iOS.
Maybe I should try to call requestNewPublishPermissions for an active session after opening new session with nil permissions?