【发布时间】: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