1

I need to implement twitter login in my iOS app, I have installed twitter framework with fabric SDK. Now for the very first time I am facing the issue while loggin in. I can able to receive the token details

Twitter Details :@TestUserApp logged in! (796637020760186880)

Auth token:796637020760186880-ieeZM2Mbn3FLutLOcJ1sk7bp83ZSlzU

Auth Token secret:1G0O5YdF89V0VtoNmdY8W3ui2pkPNvKgtNPbqrleOiIoB

Error : Error Domain=TwitterAPIErrorDomain Code=99 "Request failed: forbidden (403)" UserInfo={NSLocalizedFailureReason=Twitter API error : Unable to verify your credentials (code 99), TWTRNetworkingStatusCode=403, NSErrorFailingURLKey=https://api.twitter.com/oauth2/token, NSLocalizedDescription=Request failed: forbidden (403)}

Full Code:

TWTRLogInButton *logInButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
    if (session) {

        NSString *authToken = session.authToken;
        NSString *authTokenSecret = session.authTokenSecret;
        NSString* userId = session.userID;
        NSString *message = [NSString stringWithFormat:@"@%@ logged in! (%@) -Auth token:%@ -Auth Token secret:%@",
                             [session userName], [session userID],authToken,authTokenSecret];

        // Objective-C
        TWTRAPIClient *client = [[TWTRAPIClient alloc] init];
        [client loadUserWithID:userId completion:^(TWTRUser *user, NSError *error) {
            if (error == nil) {
                 NSLog(@"Name:%@ -- ScreenName:%@ -- ProfileImageUrl:%@",user.name,user.screenName,user.profileImageURL);
            }
            else {
                NSLog(@"Error:%@",error.description);
            }

        }];

    } else {
        NSLog(@"Login error: %@", [error localizedDescription]);
    }
}];
Rajat
  • 10,977
  • 3
  • 38
  • 55
Super Xtreem
  • 187
  • 1
  • 10
  • Follow this link https://stackoverflow.com/questions/54807221/get-twitter-friends-list/54838712#54838712 – Naresh Feb 23 '19 at 06:22

1 Answers1

0

//in app delegate

#import <Fabric/Fabric.h>
#import <TwitterKit/TwitterKit.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Fabric with:@[[Twitter class]]];
}

//your controller .m

#import <TwitterKit/TwitterKit.h>


[[Twitter sharedInstance] logInWithMethods:TWTRLoginMethodWebBased completion:^(TWTRSession *session, NSError *error)
 {
     if (session)
     {

         TWTRAPIClient *client = [TWTRAPIClient clientWithCurrentUser];
         NSURLRequest *request = [client URLRequestWithMethod:@"GET"
                                                          URL:@"https://api.twitter.com/1.1/account/verify_credentials.json"
                                                   parameters:@{@"include_email": @"true", @"skip_status": @"true"}
                                                        error:nil];

         [client sendTwitterRequest:request completion:^(NSURLResponse *response, NSData *data, NSError *connectionError)
          {

              if (data)
              {
                  // handle the response data e.g.
                  NSError *jsonError;
                  NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
                  NSLog(@"Twiiter json is ====>%@",json);

                  NSString *userid =[json objectForKey:@"id"];
                  NSString *strtwitter =[NSString stringWithFormat:@"%@",@"https://twitter.com/intent/user?user_id=",userid];
                  NSLog(@"strtwitter is ===>%@",strtwitter);

                   [self dataSendToTwitter:json];

              }
              else {
                  NSLog(@"Error: %@", connectionError);
              }


          }];



     } else {
         NSLog(@"error: %@", [error localizedDescription]);
     }
 }];
Dishant Rajput
  • 1,329
  • 1
  • 10
  • 20