Twitter にログインした後、ユーザー名やユーザー ID などの有用なデータを印刷できます。ただし、OAuth トークンは常に null です。どうすれば入手できますか?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);
}
});
}
];
私はReverse Authが必要だと「思います」が、そのチュートリアルでは不思議なことに「ステップ 1」のコードが省略されていました。