登录Twitter后如何获取oauth令牌? [英] How do I get the oauth token after logging into Twitter?

查看:97
本文介绍了登录Twitter后如何获取oauth令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

登录Twitter后,我可以打印出一些有用的数据,例如用户名和用户ID。但是,OAuth令牌始终为null。我如何得到它?我需要将OAuth令牌发送到我的服务器,以便它可以验证用户确实是他说的那个人。

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);
            }
        });
    }
];

思考我需要反向认证,但是该教程神秘地遗漏了步骤1的代码。

I "think" I need Reverse Auth, but that tutorial mysteriously left out the code for "step 1".

推荐答案

您确实需要使用反向身份验证。

You will indeed need to use Reverse Auth.

我最近使用过 Sean Cook的TWReverseAuth ,效果很好。请小心关闭供应商目录中各个文件的ARC。

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.

这篇关于登录Twitter后如何获取oauth令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆