skip to Main Content

I am new to iPhone development.I am using fabric for twitter login.For this am using this code.

[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession* session, NSError* error) {
        if (session)
        {
            NSLog(@"signed in as %@", [session userName]);
        }
        else
        {
            NSLog(@"error: %@", [error localizedDescription]);
        }
    }];

Now,i want to get user’s First name and last name from twitter.I have done R&D on this and find some code Get user profile details (especially email address) from twitter in iOS
But i am not unable to understand this code.Because it’s give some error in my code.
error is

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

2

Answers


  1. It might be too late to answer this question, but this might be helpful. Let’s say you’ve already installed the Twitter SDK in you iOS app. You can get Twitter user’s info like this:

    1. Login with twitter:

    Twitter.sharedInstance().logIn(completion: { (session, error) in }

    2. Use the TWTRAPIClient to retrieve user’s data:

    Twitter.sharedInstance().logIn(completion: { (session, error) in 
        guard let session = session else {
            print("Something went wrong.")
            return
        }        
    
        let client = TWTRAPIClient()
        client.loadUser(withID: session.userID, completion: { (user, error) in
             print("user's name: (user?.name ?? "")")
             print("user's profile picture: (user?.profileImageURL ?? "")")
        })
    }
    
    Login or Signup to reply.
  2. TWTRTwitter.sharedInstance().logIn { (twitterSession, error) in
        if let session = twitterSession {
            let client = TWTRAPIClient.withCurrentUser()
            client.loadUser(withID: session.userID, completion: { (twitterUser, userError) in
                if let user = twitterUser {
                    print("user.name -> (user.name)")
                    print("user.profileImageURL -> (user.profileImageURL)")
                    print("user.profileURL -> (user.profileURL)")
                } else {
                    print("userError: (String(describing: userError?.localizedDescription))");
                }
            })
        } else {
            print("error: (String(describing: error?.localizedDescription))");
        }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search