问题描述
我对如何使用iOS社交框架获取Twitter OAuth令牌感到困惑。假设我在iOS6上设置了Facebook和Twitter帐户,我可以获得ACAccount。当我检查Facebook ACAccount的ACAccountCredential时,OAuthToken属性已设置,但对于Twitter ACAccount,则不是。 Twitter ACAccount的其他每个细节都设置为ACAccountCredential不是。
I'm a little confused as to how I get the Twitter OAuth Token using the iOS Social Framework. Assuming I have a Facebook and Twitter account setup on iOS6, and I can get the ACAccount. When I check the ACAccountCredential for the Facebook ACAccount the OAuthToken property is set but for the Twitter ACAccount it isn't. Every other detail for the Twitter ACAccount is set just the ACAccountCredential is not.
为了增加混乱,我遇到了一篇关于使用Reverse Auth获取OAuth令牌的文章( ) 。本文讨论了如何调用并传入oauth_ *字典params params例如consumer_key,nononce等等。但是,确实将我的ACAccount附加到SLRequest是为了这个目的吗?在任何情况下,当我尝试这个时,我都会收到错误无法验证oauth签名和令牌。
To add to the confusion I came across an article on using Reverse Auth to get the OAuth Token (https://dev.twitter.com/docs/ios/using-reverse-auth). This article talks about calling https://api.twitter.com/oauth/request_token and passing in a dictionary of oauth_* params params e.g. consumer_key, nononce, etc. But, surely attaching my ACAccount to the SLRequest serves this purpose? In any event I get back the error "Failed to validate oauth signature and token" when I try this.
所以我的问题是我应该看到Twitter OAuth Token in ACAccountCredential,还是应该使用Reverse Auth?如果是这样,我是否需要显式传递包含oauth_ *参数的NSDictionary或附加足够的ACAccount?
So my question is should I be seeing the Twitter OAuth Token in the ACAccountCredential, or should I be using Reverse Auth? and if so, do I need to explicit pass in the NSDictionary containing the oauth_* params or is attaching the ACAccount sufficient?
推荐答案
让我们通过几个步骤回答这个问题,有一些事情需要解决/澄清。
Let's answer this in a few steps, there are a few things that need addressing/clarifying.
此对象用于与ACAccount对象协调,以便帐户框架能够为特定帐户验证用户。它不是为了随意阅读而设计的;它只应在您需要将帐户保存到帐户框架时使用。
This object is used in co-ordination with an ACAccount object, in order for the accounts framework to be able to authenticate the user for a particular account. It is not designed to be read at will; it is only supposed to be used when you need to save an account to the accounts framework.
说明如果您要迁移到帐户框架来管理用户的帐户而不是使用自己的服务器,或者在较旧的iOS应用程序的情况下,需要在本地管理帐户,则需要填充ACAccountCredential。
Documentation from Twitter states that you need to populate an ACAccountCredential if you're migrating to the accounts framework to manage your user's accounts, instead of using your own servers, or in the case of older iOS application, managing the accounts yourself locally.
,但您问题中的链接也会使清除哪些参数是必需的。您将需要提供自己的随机数和其他参数值。
As for the request you need to send, Twitter is not aware of ACAccounts. Remember this reverse auth process is not specific to iOS, it can be done by any computing device with access to the web. As such, you need to send a HTTP POST request to https://api.twitter.com/oauth/request_token
with the specified parameters (OAuth standard ones + x_auth_mode
). A bit more clarity on the required parameters can be found here, but the link in your question will also make clear which parameters are required. You will be required to provide your own nonce, and other parameter values.
您可以使用SLRequest类或AFNetworking向Twitter发送POST请求,并传入NSDictionary您的参数值(如Twitter的文档中的代码示例中所示 access_token
)。
You can use the SLRequest class or AFNetworking to make your POST request to Twitter, passing in an NSDictionary for your parameter values (as seen in the code sample in Twitter's documentation for access_token
).
在回答了这两点后,我认为很明显您需要使用反向身份验证才能根据需要访问正确的OAuth令牌。 Twitter文档清楚地说明了您需要做什么(它甚至提供了您可以使用的代码示例),但您需要了解一般的OAuth请求/响应管理才能这样做。您不能简单地附加ACAccount,您需要使用所需的OAuth参数填充字典,然后将其传递给您的HTTP POST请求 request_token
。我已经提供了大量的参考资料供你参考,我希望这会让你走上正确的道路。
After answering those two points, I think it's clear that you'll need to use reverse authentication in order to access the correct OAuth token for your needs. The Twitter documentation makes it clear on what you need to do (it even provides code samples that you can use), but you do need to be aware of general OAuth request/response management in order to do so. You can't simply attach an ACAccount, you need to populate a dictionary with the required OAuth parameters, and then pass this in to your HTTP POST request to request_token
. I have provided a considerable number of references for you to refer to, and I hope that'll put you on the right path.
这篇关于使用社交框架检索Twitter OAuth令牌(iOS6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!