我是iPhone开发的新手。我正在使用面料进行Twitter登录。这是使用此代码。
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession* session, NSError* error) {
if (session)
{
NSLog(@"signed in as %@", [session userName]);
}
else
{
NSLog(@"error: %@", [error localizedDescription]);
}
}];
现在,我想从twitter获取用户的名字和姓氏。我已经对此做了R& D并找到了一些代码Get user profile details (especially email address) from twitter in iOS 但我无法理解这段代码。因为它在我的代码中给出了一些错误。 错误是
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)}
答案 0 :(得分:1)
回答这个问题可能为时已晚,但这可能会有所帮助。假设您已经在iOS应用中安装了Twitter SDK。您可以获得Twitter用户的信息:
1。使用Twitter登录:
Twitter.sharedInstance()。logIn(完成:{(会话,错误)}}
2. 使用TWTRAPIClient检索用户数据:
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 ?? "")")
})
}
答案 1 :(得分:0)
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))");
}