How do I get the oauth token after logging into Twitter?

会有一股神秘感。 提交于 2019-12-22 18:23:43

问题


After logging into Twitter, I am able to print out some useful data such as the username and user ID. However, the OAuth token is always null. How do I get it? I need to send OAuth token to my server so it can verify that the user is indeed who he says he is.

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" I need Reverse Auth, but that tutorial mysteriously left out the code for "step 1".


回答1:


You will indeed need to use Reverse Auth.

I recently used Sean Cook's TWReverseAuth and it worked very well. Just be careful to turn off ARC for the individual files in the Vendor directory.



来源:https://stackoverflow.com/questions/15713472/how-do-i-get-the-oauth-token-after-logging-into-twitter

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