简体   繁体   中英

Facebook iOS SDK 3.1 | “You have already authorized YOUR_APP” appears every time user tries to login

I'm currently trying to implement the Facebook-Login-Flow with iOS Facebook SDK 3.1. But there is a little Problem with it. Every time the user logs in with facebook the webview will open up and says

"You have already authorized YOUR_APP.."

The code I wrote based on the following example: click here Now my question is, how can I avoid this behaviour and what I am doing wrong?

Please see this code ,it may help

    postParams=
    [@{
       @"link" :link,
       @"picture" :picture link , //[NSString stringWithFormat:@"%@%@",KBaseImageUrl,@"/assets/img/logo-small.jpg"],
       @"name" : @“name”,
       @"caption" : caption title,
       @"description" :discription
       } mutableCopy];
    title=[[arrayEventInfo valueForKey:@"info"] valueForKey:@"eventname"];


if ([[FBSession activeSession]isOpen])
{

    if ([[[FBSession activeSession]permissions]indexOfObject:@"publish_actions"] == NSNotFound)
    {

        [[FBSession activeSession] requestNewPublishPermissions:[NSArray arrayWithObject:@"publish_action"] defaultAudience:FBSessionDefaultAudienceFriends
                                              completionHandler:^(FBSession *session,NSError *error){

                                                      // If permissions granted, publish the story
                                                      [FBRequestConnection
                                                       startWithGraphPath:@"me/feed"
                                                       parameters:postParams
                                                       HTTPMethod:@"POST"
                                                       completionHandler:^(FBRequestConnection *connection,
                                                                           id result,
                                                                           NSError *error)
                                                       {
                                                           NSString *alertText;
                                                           if (error)
                                                           {
                                                               alertText = [NSString stringWithFormat:
                                                                            @"error: domain = %@, code = %d",
                                                                            error.domain, error.code];
                                                           }
                                                           else
                                                           {
                                                               alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
                                                               //@"Posted action, id: %@",
                                                               // result[@"id"]];
                                                           }
                                                           //Show the result in an alert
                                                           [[[UIAlertView alloc] initWithTitle:title
                                                                                       message:alertText
                                                                                      delegate:self
                                                                             cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
                                                           [FBSession.activeSession closeAndClearTokenInformation];
                                                           [FBSession.activeSession close];


                                                       }];

                                                      UIActivityIndicatorView *activityView=(UIActivityIndicatorView*)[self.view viewWithTag:111];
                                                      if(activityView)
                                                      {
                                                          [activityView removeFromSuperview];
                                                      }
                                                      [self.view setUserInteractionEnabled:YES];
                                                      [self.navigationController.navigationBar setUserInteractionEnabled:YES];




                                              }];

    }else
    {

            // If permissions granted, publish the story
            [FBRequestConnection
             startWithGraphPath:@"me/feed"
             parameters:postParams
             HTTPMethod:@"POST"
             completionHandler:^(FBRequestConnection *connection,
                                 id result,
                                 NSError *error)
             {
                 NSString *alertText;
                 if (error)
                 {
                     alertText = [NSString stringWithFormat:
                                  @"error: domain = %@, code = %d",
                                  error.domain, error.code];
                 }
                 else
                 {
                     alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
                     //@"Posted action, id: %@",
                     // result[@"id"]];
                 }
                 //Show the result in an alert
                 [[[UIAlertView alloc] initWithTitle:title
                                             message:alertText
                                            delegate:self
                                   cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
                 [FBSession.activeSession closeAndClearTokenInformation];
                 [FBSession.activeSession close];


             }];


    }
}
else
{


    [FBSession openActiveSessionWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
                                       defaultAudience:FBSessionDefaultAudienceOnlyMe
                                          allowLoginUI:YES
                                     completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
                                         if (!error && status == FBSessionStateOpen) {
                                             if (!error)
                                             {
                                                 // If permissions granted, publish the story
                                                 [FBRequestConnection
                                                  startWithGraphPath:@"me/feed"
                                                  parameters:postParams
                                                  HTTPMethod:@"POST"
                                                  completionHandler:^(FBRequestConnection *connection,
                                                                      id result,
                                                                      NSError *error)
                                                  {
                                                      NSString *alertText;
                                                      if (error)
                                                      {
                                                          alertText = [NSString stringWithFormat:
                                                                       @"error: domain = %@, code = %d",
                                                                       error.domain, error.code];
                                                      }
                                                      else
                                                      {
                                                          alertText = @"Posted successfully on your wall.";//[NSString stringWithFormat:
                                                          //@"Posted action, id: %@",
                                                          // result[@"id"]];
                                                      }
                                                      //Show the result in an alert
                                                      [[[UIAlertView alloc] initWithTitle:title
                                                                                  message:alertText
                                                                                 delegate:self
                                                                        cancelButtonTitle:@"OK" otherButtonTitles:nil]show];
                                                      [FBSession.activeSession closeAndClearTokenInformation];
                                                      [FBSession.activeSession close];


                                                  }];

                                             }
                                         }else{
                                             NSLog(@"%@",[error description]);
                                             UIActivityIndicatorView *activityView=(UIActivityIndicatorView*)[self.view viewWithTag:111];
                                             if(activityView)
                                             {
                                                 [activityView removeFromSuperview];
                                             }
                                             [self.view setUserInteractionEnabled:YES];
                                             [self.navigationController.navigationBar setUserInteractionEnabled:YES];

                                         }
                                     }];
}

If you are testing the code in dev then the first time you log in it will store that session on Facebook.

So, you try to test it again but it is already authorized.

If you want to test the login process again then go to Facebook and de-authorize your app (it will be in your list of apps).

Then you can log in again on the device.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM