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

  • SEARCH
  • Home
  • 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 6364247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:08:23+00:00 2026-05-25T00:08:23+00:00

I’m using FBConnect sdk in order to publish posts to a user’s profile via

  • 0

I’m using FBConnect sdk in order to publish posts to a user’s profile via my application. I’m having a number of problems with this:

When the relevant code runs for the first time on the device, the user is re-directed, as wanted, to the facebook app/website, which asks him to authorize it. if the user authorizes it, it returns back to the application, which pops a “Connect to facebook” view controller which asks the user to log in. this is weird, as the user is already logged in, otherwise how could he authorize the app? but I guess this may be ok, as he hadn’t logged in through the app yet. after he logs in, it does nothing. only the second time the code gets run, after he authorized the app, the user gets the posting dialog.

If the user hadn’t authorized the app, when it comes back to my app after the authorization dialog, it asks the user to login ( just as if he authorized ), and does nothing after he had logged in. only the second time the code gets ran, the authorization dialog opens, with the optinos “Authorize” & “Leave App”, instead of “Authorize” & “Don’t authorize” / “Allow” & “Don’t Allow”.

In addition, if the user has deleted his authorization via his account’s settings on facebook, instead of just asking him to re-authorize it, a facebook dialog pops ( instead of the post/authorization dialog ), saying: “An error occurred. Please try again later.” Trying later doesn’t help. it will pop always, even if u restart the app. the only way to make it go away is to re-install the app, which will cause it to re-pop the authoriziation dialog.

So here’s what I want to achieve:

  1. After the user authorizes the app, he wouldn’t have to log in again.
  2. After the user authorizes the app, the posting dialog will pop immedietly, without him having to re-run the code ( which is triggered, btw, with a button ).
  3. If the user un-authorizes the app, he will be prompted again with the authorization dialog, instead of the error dialog
  4. If he refused the authorization, I will call a function that displays an error/etc.

Here’s the relevant code:

MyViewController.m

- (void)shareOnFacebook
{
    Facebook *facebook = [[Facebook alloc] initWithAppId:myAppID];
    [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] setFacebook:facebook];
    [facebook release];
    facebook = [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] facebook];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }
    if (![facebook isSessionValid]) {
        [facebook authorize:[NSArray arrayWithObjects:@"publish_stream", nil] delegate:(MyAppDelegate *)[[UIApplication sharedApplication] delegate]];
    }

     NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
     //Giving the dictionary some parameters for posting defaults
     [facebook dialog:@"feed" andParams:dictionary andDelegate:self]; //Note: we have 2 different delegates! appDelegate for connections & url switching, and self for dialogs
}

MyAppDelegate.h

@interface MyAppDelegate : NSObject <UIApplicationDelegate, FBSessionDelegate, FBDialogDelegate>
{  
    Facebook *facebook; // kept for facebook sharing, accessed only from MyViewController although delegate methods are handeled in here
}
@property (nonatomic, retain) Facebook *facebook;

@end

MyAppDelegate.m

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

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

Is it possible that I’m missing a couple of delegate functions on MyViewController? Because I see for some reason I’ve marked it as implementing the FBDialogDelegate protocol, although he doesn’t implement any function from there.

I’d be really glad if you guys would help me, as this is extremely frustrating for me. I couldn’t find nothing about this on the internet, and I feel like im drowning in here.

Tnx in advance!

  • 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-25T00:08:23+00:00Added an answer on May 25, 2026 at 12:08 am

    First:

    [facebook authorize:[NSArray arrayWithObjects:@"publish_stream",@"offline_access",nil] delegate:self];
    

    The offline_access key here will keep your auth token alive forever (or, more specifically, until the user manually de-authorizes your application in their application settings in their Facebook account settings). Also, set your active VC as the delegate (more on that later).

    Secondly:

    -(void)popUserShareFeed {
      NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
      //Giving the dictionary some parameters for posting defaults
      [facebook dialog:@"feed" andParams:dictionary andDelegate:self];
    }
    

    Call this method (or one like it) in your -fbDidLogin delegate method. Also call it in your original method if the session was still valid, i.e.:

    if (![facebook isSessionValid]) {
            [facebook authorize:[NSArray arrayWithObjects:@"publish_stream", nil] delegate:(MyAppDelegate *)[[UIApplication sharedApplication] delegate]];
    } else {
      [self popUserShareFeed];
    }
    

    …and your new fbDidLogin:

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

    (Note: you’ll have to define this in MyViewController.m and use it as your FBSessionDelegate. It will be functionally equivalent. Your AppDelegate does not need to also be your FBSessionDelegate.

    Third:

    Implement the -fbDidNotLogin:(BOOL)cancelled FBSessionDelegate method, like so:

    -(void)fbDidNotLogin:(BOOL)cancelled {
       if (cancelled) {
          ... some alert about the user cancelling...
       } else {
          ... some alert about how it failed for some reason...
       }
    }
    

    Fourth, as far as your bizarro errors go: A) the Facebook SDKs in general are not great, and B) I’d only set the auth token and the expiration date on your facebook object if

    A) you don’t already have one instantiated (i.e., it’s nil)

    and

    B) the expirationDate you’re setting is in the future (i.e. timeIntervalSinceNow [the NSDate instance method] called on it returns > 0).

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

Sidebar

Related Questions

No related questions found

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.