7

I'm trying to implement the new oAuth2 facebook SDK into my app but can't for the life of me understand how I'm supposed to get back to my app once logged in/authenticated.

My goal is to post a message on the users wall.

I am currently starting the login procedure with this:

-(void)tryFBlogin {

NSString *appId = @"113142482******";

NSArray *permissions =  [[NSArray arrayWithObjects:@"publish_stream",nil] retain];

TheAppDelegate *theAppDelegate = (TheAppDelegate *)[[UIApplication sharedApplication]delegate];

//Asking for permission
theAppDelegate = (TheAppDelegate *)[[UIApplication sharedApplication] delegate];
theAppDelegate.facebook = [[Facebook alloc] initWithAppId:appId andDelegate:self];
Facebook *fb = [theAppDelegate facebook];
[fb  authorize:permissions];

}

which is opening a safari browser. If I'm already logged in and have the app authorized a message will tell me so and I have an OKay button to press.

When I press the OKay button I get an alert saying safari cannot open the page. I confirm the alert and am left looking at a blank safari window.

If I'm logged out of facebook I am presented with the login screen which I fill in and am then presented with the same as above.

I understand that I haven't implemented the publish command anywhere yet as I don't know where/when this should be implemented.

I do have this delegate method in place but this seems to never get called

- (void)fbDidLogin {

    NSLog(@"fbDidLogin");
}

This is the code I have waiting to place somewhere:

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"113142482******",
facebookUrl, @"link",
@"http://www.domain.com", @"picture",
@"My Message", @"name",
@"Caption text!", @"caption",
@"Message text.",  @"message",
nil];

[facebook dialog:@"feed" andParams:params andDelegate:self];

I also have the following methods in my apps main AppDelegate:

-(BOOL) application:(UIApplication *)application handleOpenURL:(NSURL *)url{
    [facebook handleOpenURL:url]; 
return YES; 
}

Any help/suggestions would be very much appreciated.

Thanks

Mark

crooksy88
  • 3,849
  • 1
  • 24
  • 30
  • Did you registered your app to open callback from the facebook sdk in your plist (CFBundleURLTypes)? – mja Oct 05 '11 at 19:49
  • Not sure if this was my stupidity or unclear instructions but my issue was defining fb[113142482******] when it needs to be fb113142482******. That is without the square braces. – crooksy88 Oct 07 '11 at 07:16

3 Answers3

25

I had this same problem. Just to clarify some of the other answers, here's how I fixed the issue for my iPhone app in Xcode 4.2:

.plist file
    "URL types"
    "Item 0"
        "URL Schemes"
        "Item 0"
            "fb21593853845xxxx"
Greg M. Krsak
  • 2,102
  • 1
  • 18
  • 28
  • Can you elaborate a bit more on this? What is the "fb21593853845xxxx" value? – Dermot Oct 17 '11 at 12:58
  • 1
    Sure! That is the value of the "App ID/API Key" field (as found on your developers.facebook.com/apps page, under Settings) with a "fb" prefix added per the Facebook iOS SDK documentation. – Greg M. Krsak Oct 21 '11 at 05:30
  • I swear that tutorial could have emphasize the "fb" letter requirements. It just says fbYOUR_APP_ID, I assumed it was just the number. I never thought I would need the "fb" infront of the numbers. – Zhang Apr 21 '12 at 06:51
  • @GregKrsak Hey could somebody help me out with this? The above answer han'st worked for me, is there anything else I'm missing?? I've tried to hours to fix my URL Scheme but I have no idea what else to do... – Apollo Jun 06 '12 at 02:47
  • @derek.lo No problem. Check my profile and shoot me an email anytime! – Greg M. Krsak Jun 12 '12 at 19:47
0

Arg, you better open .plist as code source, you should see :

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fb38*******</string>
        </array>
    </dict>
</array>
Thomas Decaux
  • 21,738
  • 2
  • 113
  • 124
-1

You must write your AppID to your .plist

Okan
  • 11
  • 1
  • 6