Login with Twitter on iOS

点点圈 提交于 2019-12-10 00:03:36

问题


I have a problem with twitter login on iOS. If the user has account set in Settings application, I get the following error:

[TwitterKit] did encounter error with message "User's system account credentials are invalid.": Error Domain=TWTRLogInErrorDomain Code=7 "The system account credentials are no longer valid and will need to be updated in the Settings app." UserInfo={NSLocalizedDescription=The system account credentials are no longer valid and will need to be updated in the Settings app., NSLocalizedRecoverySuggestion=The user has been prompted to visit the Settings app.}

And the credentials are valid, I double check that. If there are no account in Settings app, my login goes as expected. The method I call is:

Twitter.sharedInstance().logInWithCompletion {(session, error) -> Void in

回答1:


Twitter.sharedInstance().logIn { session, error in
        if (session != nil)
        {
            print("signed in as \(session!.userName)");
            let client = TWTRAPIClient.withCurrentUser()
            let request = client.urlRequest(withMethod: "GET",
                url: "https://api.twitter.com/1.1/account/verify_credentials.json",
                parameters: ["include_email": "true", "skip_status": "true"],
                error: nil)
            client.sendTwitterRequest(request)
            { response, data, connectionError in
                print(response)
            }
        }
        else
        {
            print("error: \(error!.localizedDescription)");
        }
        }
    }

this helps me in swift3




回答2:


I think the following method should also work.

Twitter.sharedInstance().logIn(withCompletion: {(session: TWTRSession, error: Error) -> Void in
    if session {
        print("@\(session.userName()) logged in! (\(session.userID()))")
    }
    else {
        print("error: \(error!.localizedDescription)")
    }
})

It takes the account credentials from the Settings Twitter app.

More to look into: - AppDelegate.m

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]) -> Bool {
    //Twitter
    Twitter.sharedInstance().start(with: kTwitterConsumerKey, consumerSecret: kTwitterConsumerSecret)
    Fabric.with([Twitter.sharedInstance()])
    return true
}
  • Info.plist




回答3:


Solved my problem by using method:

Twitter.sharedInstance().logInWithMethods(TWTRLoginMethod.WebBased, completion: {(session, error) -> Void in

But still think other method should work as well.




回答4:


I did it like using the below code, Might be it Help

 TWTRTwitter.sharedInstance().logIn(with: self, completion: { session, error in
        if (session != nil) {
            let client = TWTRAPIClient.withCurrentUser()
          }
   }


来源:https://stackoverflow.com/questions/40018848/login-with-twitter-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!