Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6554659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:43:35+00:00 2026-05-25T12:43:35+00:00

I am stumped by the Facebook API for logging in. I can’t find anything

  • 0

I am stumped by the Facebook API for logging in. I can’t find anything helpful on the net.

My FBSessionDelegate methods are not being called, and accessToken and expirationDate values are not being set, so I don’t think I am ever logged in.

I reverted to a very simple app, with only two buttons (log in, log out) and a label to see status information.

Here is the code for the view controller, where all the processing takes place:

// 
#import <UIKit/UIKit.h>
#import "Facebook.h"

@interface facebook_login_testViewController : UIViewController <FBSessionDelegate>{

    UIButton *loginButton;
    UIButton *logoutButton;
    UILabel *info;

    Facebook *facebook;

}

@property (nonatomic, retain) Facebook *facebook;

- (void) loggingIn;
- (void) loggingOut;

@end

and

#import "facebook_login_testViewController.h"

@implementation facebook_login_testViewController
@synthesize facebook;

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [loginButton setTitle: @"Log In" forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(loggingIn) forControlEvents:UIControlEventTouchUpInside];
    loginButton.frame = CGRectMake(200, 200, 200, 50);

    logoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [logoutButton setTitle: @"Log Out" forState:UIControlStateNormal];
    [logoutButton addTarget:self action:@selector(loggingOut) forControlEvents:UIControlEventTouchUpInside];
    logoutButton.frame = CGRectMake(200, 300, 200, 50);

    info = [[UILabel alloc] initWithFrame:CGRectMake(200, 400, 400, 600)];
    info.numberOfLines = 0;

    [self.view addSubview:loginButton];
    [self.view addSubview:logoutButton];
    [self.view addSubview:info];

    info.text = @"Waiting to log in...\n\nPress the login button.";

    facebook = [[Facebook alloc] initWithAppId:@"159...........5" andDelegate:self];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

}


- (void)viewDidUnload
{
    [super viewDidUnload];        
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

- (void) loggingIn{
    if (![facebook isSessionValid]) {
        [facebook authorize:nil];
    }
}

- (void) loggingOut{
    info.text = [NSString stringWithFormat:@"\naccess token: %@\nexpiration date: %@\nfacebood description:%@\n",facebook.accessToken, facebook.expirationDate, facebook];
    [facebook logout:self];

}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {

    return [facebook handleOpenURL:url]; 
}

- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];

}

@end

The .plist file is set up like this

enter image description here

This really looks too simple to get wrong. When I click the login button, I can trace through authorize:permission, and then authorize:permissions localAppId:localAppId, and as far as I can trace it, I don’t see anything that looks like it’s going to results in isSessionValid becoming TRUE.

I wait and then press the log off button, and take a look at some Facebook parameters, in case something asynchronous needed to occur, and they are still null.

Can someone see what I am missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T12:43:36+00:00Added an answer on May 25, 2026 at 12:43 pm

    There are few examples on the net that show how this works, but the Facebook SDK is distributed with a demo app (DemoApp) that works once you plug in the appId. (If you don’t plug in the appId value, it will get killed when it checks for that value.)

    What is happening in the authorization process is that [facebook authorize:permissions] is called. (permissions should not be nil)

    This leads to a call to [self authorize:permissions localAppId:nil], which then calls [self authorizeWithFBAppAuth:YES safariAuth:YES]. In that method, three ways of connecting to facebook for authorization can be tried.

    In each of these asynchronous methods, the application delegate is the delegate that handles the resulting callback as part of the to application:(UIApplication *)application handleOpenURL:(NSURL *)url. If this was mentioned in the other online tutorials, it’s easy to miss, because they generally do all of the processing within the application delegate, from what I saw. In my case, I did the main processing within the main view controller.

    The fix, in my case, was to move the application:(UIApplication *)application handleOpenURL:(NSURL *)url method to the application delegate and point it to the facebook object like this:

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

    After that, the other facebook delegate methods (fbDidLogin, fbDidLogout) were called and I received the accessToken and expirationDate. So it looks like this is working now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really stumped on this issue. I have a problem where Java can't find
I'm stumped why this doesn't work can't seem to find any problems. Here is
I am completely stumped as to why this code does not get any SDL
I am greatly stumped How can I use an iterator in C# like a
I'm stumped with a problem in ASP.NET MVC 3 - handling editing and updating
This one has me stumped. I've searched and found similar questions but I can't
Quite stumped on this one. I am using the Youtube JS API to determine
I'm stumped. Why would a query work in phpMyAdmin but not in a MAMP
I'm stumped by a seemingly simple problem. In my ASP.NET page, I have a
I'm stumped, hopefully I've just done a dumb thing that I can fix easily.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.