【问题标题】:Looking for OAuth version of Twitter code for iOS client为 iOS 客户端寻找 OAuth 版本的 Twitter 代码
【发布时间】:2011-07-30 02:13:21
【问题描述】:

我正在从 Head First iPhone Programming 一书中学习 iOS 编程。在一个练习中,他们提供了使用基本授权的 Twitter 示例代码。既然 Twitter 使用 OAuth,我如何获取 OAuth 代码以便测试我的客户端?我需要在 Twitter 上注册我的应用程序吗?我该怎么做,因为它只是一个测试应用程序?

这里是基本授权版本的代码;我正在寻找 OAuth 版本:

//TWITTER BLACK MAGIC
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://YOUR_TWITTER_USERNAME:YOUR_TWITTER_PASSWORD@twitter.com/statuses/update.xml"]
                                                        cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                    timeoutInterval:60.0];

[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[[NSString stringWithFormat:@"status=%@", themessage] dataUsingEncoding:NSASCIIStringEncoding]];
NSURLResponse* response;
NSError* error;
NSData* result = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
NSLog(@"%@", [[[NSString alloc] initWithData:result encoding:NSASCIIStringEncoding] autorelease]);

//END TWITTER BLACK MAGIC 

【问题讨论】:

  • 呃,这太不安全了:/
  • 这就是他们从基本授权更改为 OAuth 的原因。如何获取令牌以使用 OAuth?
  • 我不知道,我只知道以明文形式发送密码是个坏主意。

标签: xcode ios twitter twitter-oauth


【解决方案1】:

要获得 Twitter oAuth 访问权限,您需要在 http://dev.twitter.com 上创建应用并检索消费者密钥和消费者身份验证。

也许本教程会对您有所帮助:

http://mobile.tutsplus.com/tutorials/iphone/twitter-api-iphone/

【讨论】:

    猜你喜欢
    • 2011-04-25
    • 2011-12-04
    • 2021-11-23
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多