Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 648
Sebastian Boldt Avatar asked Dec 19 '12 09:12

Sebastian Boldt


People also ask

What is Facebook SDK for IOS?

The Facebook SDK enables: Facebook Login - Authenticate people with their Facebook credentials. Share and Send dialogs - Enable sharing content from your app to Facebook. App Events - Log events in your application.


1 Answers

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];

                                         }
                                     }];
}
like image 130
Alok Chandra Avatar answered Sep 21 '22 05:09

Alok Chandra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!