1.https://developer.twitter.com/en/apps
2.创建app
3.添加app的信息,特别注意callback URLS不能随便写,需要填写为一下格式:twitterkit-<consumerKey>,
consumerKey 是Twitter API key, 例如:twitterkit-dwLf79lNQfsJ.
如不填写成这种格式会报错:[TwitterKit] Error obtaining user auth token.403错误
4.项目的plist文件中配置,twitterkit-<consumerKey>,consumerKey 是Twitter API key, 例如:twitterkit-
dwLf79lNQfsJ.plist文件打开方式sourceCode,添加以下内容
<key>CFBundleURLTypes</key>
<key>CFBundleURLSchemes</key>
<string>twitterkit-<consumerKey></string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>twitterkit</string>
<string>twitterauth</string>
</array>
5.这样就配置好了,最后在需要调用Twitter登录的地方加入一下代码,其他方法可以参考:https://github.com/twitter/twitter-kit-ios
[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
if(session) {
DLog(@"signed in as %@", [session userName]);
}else{
DLog(@"error: %@", [error localizedDescription]);
}
}];