登录 Twitter 后,我可以打印一些有用的数据,例如用户名和用户 ID。但是,OAuth 令牌始终为空。我怎样才能得到它?我需要将 OAuth 令牌发送到我的服务器,以便它可以验证用户确实是他所说的人。
ACAccountStore* accountStore = [[ACAccountStore alloc] init];
ACAccountType* twitterType = [self.context.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore
requestAccessToAccountsWithType:twitterType
withCompletionHandler:^(BOOL isAllowed, NSError* error) {
dispatch_sync(dispatch_get_main_queue(), ^(void) {
if (isAllowed) {
ACAccount* account = [[self.context.accountStore accountsWithAccountType:[self.context.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter]] lastObject];
NSLog(@"username = %@", account.username);
NSLog(@"user_id = %@", [[account valueForKey:@"properties"] valueForKey:@"user_id"]);
// ouath token is always null
NSLog(@"oauth token = %@", account.credential.oauthToken);
}
});
}
];
I "think“ 我需要反向验证 https://dev.twitter.com/docs/ios/using-reverse-auth,但该教程神秘地遗漏了“步骤 1”的代码。
您确实需要使用反向验证。
我最近用过肖恩·库克的 TWReverseAuth https://github.com/seancook/TWReverseAuthExample效果非常好。只是要小心关闭 ARC 中的各个文件Vendor
目录。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)