10

After updating the Facebook sdk to 3.5, when trying to perform openActiveSessionWithReadPermissions the operation fails. Here is the snippet for opening the session and handling the callback:

[FBSession openActiveSessionWithReadPermissions:@[@"email", @"user_hometown", @"user_location", @"user_birthday"]
                                   allowLoginUI:YES
                              completionHandler:
 ^(FBSession *session,
   FBSessionState state, NSError *error) {
     switch (state) {
         case FBSessionStateCreatedTokenLoaded:
         case FBSessionStateOpenTokenExtended:
         case FBSessionStateOpen:
         {
             completion(TRUE);
             break;
         }
         case FBSessionStateClosed:
         case FBSessionStateClosedLoginFailed:
             completion(FALSE);
             [FBSession.activeSession closeAndClearTokenInformation];
             break;
         default:
             break;
     }
 }];

I end up in the FBSessionStateClosedLoginFailed case and I get a FBSKLog as follows:

FBSDKLog: Cannot use the Facebook app or Safari to authorize, fb123456789012345 is not registered as a URL Scheme
alexgophermix
  • 4,189
  • 5
  • 32
  • 59

6 Answers6

25

I Had the same problem (Facebook SDK 3.5.1)

My URL scheme for Facebook was on Item 1 in the Info.plist URL schemes. Problem fixed by moving it to Item 0.

iwasrobbed
  • 46,496
  • 21
  • 150
  • 195
Lola
  • 366
  • 2
  • 5
16

I had the same problem. The code above fixed this issue. U have to edit your .plist file with text editor. But in Xcode u will not see any changes. Instead of URL Types - CFBundleURLTypes and instead of URL Schemes should be CFBundleURLSchemes.

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb48524**********</string>
        </array>
    </dict>
</array>
Sapozhnik Ivan
  • 235
  • 3
  • 7
10

It seems that I had a URL Scheme that didn't match my FacebookAppId. For whatever reason this didn't seem to be a problem before but is relevant now. Make sure your Facebook URL Scheme is your FacebookAppID prefixed with fb (in your .plist files). For example:

FacebookAppId: 123456789012345

URL types -> Item 0 -> URL Schemes -> Item 0: fb123456789012345

alexgophermix
  • 4,189
  • 5
  • 32
  • 59
2
adding URL Scheme in plist file is solved my problem

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb8947128947(fb<App ID>)</string>
        </array>
    </dict>
</array>
</plist>
Hardik Darji
  • 3,633
  • 1
  • 30
  • 30
2

I am getting the same error but solved by below info.plist hierarchy:

`
 <key>URL Types</key>
 <array>  
   <dict>
     <key>URL Schemes</key>    
     <array>      
      <string>fb***</string>    
     </array>    
   </dict> 
 </array>
`
alexzg
  • 845
  • 8
  • 8
Mehul Chuahan
  • 752
  • 8
  • 19
  • 1
    Welcome to StackOverflow! This answer only discusses that it might solve the problem. Would be good if you can also give rational as to why and how it will fix the problem and why did it happen in the first place. – Nilesh Sep 12 '14 at 08:03
1

Lola's answer worked for me. If you have multiple URL Types - e.g. Facebook's and one for your app - it's helpful to give the one you handle yourself a bundle identifier equal to your app's bundle identifier, then iterate through your URL Types to find it.

At the beginning of my app delegate I just run:

NSArray *urlSchemes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"];
for (NSDictionary *scheme in urlSchemes) {
    if ([[scheme objectForKey:@"CFBundleURLName"] isEqualToString:[[NSBundle mainBundle] bundleIdentifier]]) {
        self.urlScheme = [[scheme objectForKey:@"CFBundleURLSchemes"] objectAtIndex:0];
        break;
    }
}

and then (since we have multiple environments with different FB App Ids)

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    if ([url.scheme hasPrefix:@"fb"]) {
        //Facebook callback
        return [FBSession.activeSession handleOpenURL:url];
    // else handle your own URL here
seth-cameo
  • 11
  • 1