gpt4 book ai didi

iphone - Twitter + oAuth 噩梦

转载 作者:行者123 更新时间:2023-12-03 19:43:01 26 4
gpt4 key购买 nike

我正在尝试实现 Twitter 的自定义登录 View (我不想要那个 UIWebView)。我已经下载了很多类(class),但到目前为止我对此感到噩梦。现在我正在尝试让 Twitter + oAuth 发挥作用。这是演示代码(有效):

_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
_engine.consumerKey = kOAuthConsumerKey;
_engine.consumerSecret = kOAuthConsumerSecret;

[_engine requestRequestToken];

UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self];

if (controller)
[self presentModalViewController: controller animated: YES];
else
[_engine sendUpdate: [NSString stringWithFormat: @"Already Updated. %@", [NSDate date]]];

现在我想做的是将 SA_OAuthTwitterController 替换为自定义 UITextFields。所以我正在尝试这个:

_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate: self];
_engine.consumerKey = kOAuthConsumerKey;
_engine.consumerSecret = kOAuthConsumerSecret;

[_engine requestRequestToken];
[_engine requestAccessToken];
[_engine setUsername:@"username" password:@"password"];
[_engine sendUpdate:@"tweet"];

但我不断收到错误 401。我可能错过了一个步骤。有人吗?

最佳答案

您要消除的 View Controller 会加载一个 Web View ,提示用户使用 Twitter 验证您的应用程序。如果您从未让用户进行身份验证,您将无法进行经过身份验证的 Twitter 调用。有一种方法可以完成您想要的操作,但是您必须自己完成所有 OAuth 步骤。以下是 different web service (Vimeo) 中指定的步骤,但适用相同的规则:

  1. Your application sends a request with your consumer key, and signed with your consumer secret, for a something called a request token. If we verify your application correctly, we'll send you back a request token and a token secret.

  2. You'll then create a link for the user to click on with the request token.

  3. When the user gets to Vimeo, they'll be prompted to allow your application access to their account. If they click yes, we'll send them back to your application, along with a verifier.

  4. You'll then use the request token, verifier, and token secret to make
    another call to us to get an access token. The access token is what you'll use to access the user's information on Vimeo.

OAuth 确实令人头疼,所以祝你好运。 ;-)

关于iphone - Twitter + oAuth 噩梦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1830736/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com