English 中文(简体)
Facebook Connect login dialog not working
原标题:

I am using Facebook Connect for iPhone and following the official instructions. I use the following code to display the login dialog:

FBLoginDialog* dialog = [[[FBLoginDialog alloc] initWithSession:session] autorelease];
[dialog show];

(Note that the results are the same when I go with the FBLoginButton approach instead of showing the dialog directly.)

The dialog pops up as expected, but as you see in the screenshot below, it is way too large and looks like the full Facebook homepage. I can pan the dialog to reveal the login button, but once I log in it proceeds to show the regular Facebook page inside the dialog. It never calls my session:didLogin callback.

Is there something I m doing wrong?

alt text http://img.skitch.com/20091115-t24w7p5gpa6iqgehjdc4f1awfs.jpg

最佳回答

I finally figured it out... I was initializing the FBSession inside my app delegate s applicationDidFinishLaunching method. I then triggered the Facebook login code in my view controller s viewDidAppear.

However, applicationDidFinishLaunching looked like this:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    self.session = [FBSession sessionForApplication:FB_API_KEY secret:FB_APP_SECRET delegate:self];
}

This means that I was showing the window before I was initializing the FBSession, and apparently a nil session leads to the behavior I described above. After changing applicationDidFinishLaunching to create the FBSession first, everything now works as expected. Doh... ;)

问题回答

Thanks Mirko, I had the exact same problem but reached via a different implementation. Here are the facts:

  • The problem was the same on the simulator and on a physical device. The wrong user agent is a red herring.
  • Before displaying the dialog (either directly via FBLoginDialog or using the FBLoginButton), you must have established your session (either via "[[FBSession sessionForApplication:kApiKey secret:kApiSecret delegate:self] retain];" or the proxy method). Or calling [session resume] on an already existing session.
  • The state of the session object before displaying the dialog has no effect. As long as I have called the above methods to establish my session, I can do "session = nil" or "[session logout]", and I still get the correct dialog. If I do not establish my session first, I get the wrong full homepage effect.

I haven t worked with the FaceBook API library, but did you try changing dialog.frame before sending the show message?

Have you tried this on a device? What OS are you building against? I m using an almost identical call with no problems (-init, vs. initWithSession). Also, I m assuming you have a window and view architecture already set up behind this, correct?

I only had this problem, only the device, not on the simulator. Apparently the Facebook page is using the device s user agent to render the correct page. If you wanted to, you should be able to change that by adding a User Agent header to the http calls FB Connect s Web View is making.

I just pulled up my code and saw that I wrote a workaround for the same problem. Basically the issue is Facebook connect wants you to put a FBLoginButton in your app, which then opens up the Login Dialog. In order to display the dialog without the button I did this:

faceBookSession = [FBSession sessionForApplication:kFacebookAPIKey secret:kFaceBookAPISeceret delegate:self];
    if (![faceBookSession resume]) {
        FBLoginButton *button = [[FBLoginButton alloc] init];
        [button performSelector:@selector(touchUpInside)];
        [button release];
    }




相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签