我正在从《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
最佳答案
要获得 Twitter oAuth 访问权限,您需要在 http://dev.twitter.com 上创建应用程序并检索 Consumer Key 和 Consumer Auth。
也许本教程可以帮助您:
http://mobile.tutsplus.com/tutorials/iphone/twitter-api-iphone/
关于xcode - 为 iOS 客户端寻找 OAuth 版本的 Twitter 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5554430/