FBSession openActiveSessionWithPublishPermissions com.facebook.sdk, code = 2 - ios

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?

Related

ios facebook sdk error systemlogincancelled

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.

read and publish permission in facebook sdk 3.0 iOS

In the last SDK, read and publish permissions are separated. So, in my code, whenever the users logs in I am using this code:
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
I have seen in the facebook developer that when I want to publish, I should ask for publish permissions like this:
// can include any of the "publish" or "manage" permissions
NSArray *permissions =
[NSArray arrayWithObjects:#"publish_actions", nil];
[[FBSession activeSession] reauthorizeWithPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error) {
/* handle success + failure in block */
}];
Since this is my first app that I am using facebook integration, I want to ask a couple of things:
1) Can these sessions be open at the same time? I will ask for the publish permissions only when the user wants to publish, but should I do something else with the other session? Like close it first, and reopen it later or I should not worry about?
2) If I have a postToFriends button for example, my pseudocode for making it work would be like this, right?
- (IBAction)postToFriendaction:(id)sender {
if (!FBSession.activeSession.isOpen) {
/* code from the above for enabling publish permissions*/
}
or I should change !FBSession.activeSession.isOpen to something else, because no the user is logged in with read permission only, he never enters the if clause. Can you help me?
The two sessions you refer to are actually the same session (it's the "active" session that's statically available after a call to openActiveSession... is called). So you don't need to do anything with the other session.
You should have a look at either the Scrumptious or Hello Facebook sample apps that ship with the SDK. They both give examples on how to post (while asking for publish permissions).

Facebook iOS Error Login Dialog Write privacy is not specified

Has anyone solved this error message when a user is in the login flow? I tried to toggle my default privacy settings in DevCenter -> Permissions.
I am using the deprecated method in order to both get read and right permissions at the same time. I have other apps successfully using this method.
- (void)openSession
{
[FBSession openActiveSessionWithPermissions:[[NSArray alloc] initWithObjects:#"email",#"publish_actions",#"user_birthday", nil] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
[self sessionStateChanged:session state:status error:error];
}];
}
I've already replied to your bug report on our developer website(https://developers.facebook.com/bugs/568170979870794).
If you're entering the FacebookDisplayName in your .plist file, it will opt you in for read-write permissions split. What this means is that you can no longer request read/write permissions together(using our deprecated openActiveSessionWithPermissions call). This is not a breaking change but is by design.
Set sandbox mode to no in your application settings in facebook.
I was able to fix this by removing the newly added FacebookDisplayName property ( as of FB SDK 3.5) from the *.plist file.
Opened a bug # facebook:
https://developers.facebook.com/bugs/568170979870794

iOS – Facebook SDK 3.1.1 access alert doesn't show after app is removed from facebook.com

If remove my app from Facebook App Center and then I try to authorize my app with
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
The alert ("Don't allow", "OK") that should be displayed requesting for access is not shown, instead when the completion handler is called FBSessionState will be FBSessionStateOpen which is wrong.
The second time I try to authorize it will always show the access alert correctly.
Am I the only one experiencing this? Is there a solution for this issue?
We now have better error handling in our new SDK 3.2.
Please check out our new SDK release 3.2 here: https://developers.facebook.com/blog/post/2013/02/25/facebook-sdk-3-2-for-ios/

Facebook permission Facebook SDK for iOS 5

I am developing a facebook app and is wondering how to set the permission array.
in the Facebook SDK version before all I need to do is create an instance from Facebook.h and set the permission. But now the facebook.h file is no long there, and stopped work for SDK3.0 and 3.1.
Facebook said to import the depreciated files but if I do that I get lots of errors, so that didn't work at all.
and I cannot find any documents regard setting permission property on iOS 5 and later, could someone help me out?
thanks!!
[FBSession openActiveSessionWithPublishPermissions:[[NSArray alloc] initWithObjects:#"publish_stream",#"email", nil]
defaultAudience:FBSessionDefaultAudienceFriends
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
you can find a short tutroail and simple code samples in http://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/3.1/

Resources