简体   繁体   English

Twitter(适用于iOS),oauth_nonce和发送帖子请求?

[英]Twitter for iOS, oauth_nonce & sending post request?

I'm trying to get reverse_oauth to work on an iPhone application, but I've encountered some problems regarding the POST request and what values I actually should send, so my question is two-fold. 我正在尝试使reverse_oauth在iPhone应用程序上工作,但是我遇到了一些有关POST请求以及实际应发送的值的问题,所以我的问题有两个。

I'm trying to follow the guide that twitter posted here: https://dev.twitter.com/docs/ios/using-reverse-auth 我正在尝试遵循Twitter在此处发布的指南: https : //dev.twitter.com/docs/ios/using-reverse-auth

The first question regards to oauth_nonce, or rather how do I get the value to send in? 第一个问题与oauth_nonce有关,或者更确切地说,我如何获取要发送的值? I get that oauth_nonce is a random generated string hashed by the algorithm HMAC-SHA1, but should I generate a random string that is hashed every time I want to make a request? 我得到oauth_nonce是由HMAC-SHA1算法散列的随机生成的字符串,但是我是否应该生成一个随机的字符串,该字符串在每次我想发出请求时都散列? Or is it a value that should be hashed based on something? 还是应该基于某些内容进行哈希处理的值?

And my POST request currently looks like this: 而且我的POST请求当前如下所示:

NSString *twitterUrlToPing = @"https://api.twitter.com/oauth/request_token";

NSURL *twitterUrl = [NSURL URLWithString:twitterUrlToPing];

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:twitterUrl];
[req addValue:@"xxx" forHTTPHeaderField:@"oauth_consumer_key"];
[req addValue:@"xxx" forHTTPHeaderField:@"oauth_nonce"];
[req addValue:@"HMAC-SHA1" forHTTPHeaderField:@"oauth_signature_method"];
[req addValue:timeStampString forHTTPHeaderField:@"oauth_timestamp"];
[req addValue:@"1.0" forHTTPHeaderField:@"oauth_version"];
[req addValue:@"reverse_auth" forHTTPHeaderField:@"x_auth_mode"];

[req setHTTPMethod:@"POST"];

NSLog(@"twitterHeaderPostvalues: %@", [req allHTTPHeaderFields]);

NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
NSString *content = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

NSLog(@"contentResponseFromTwitter: %@", content);

Is this the correct way to send the request, and if not how should it look like? 这是发送请求的正确方法吗?如果不是,应该是什么样?

Joakim, may I suggest taking a look at this example... https://github.com/seancook/TWReverseAuthExample Joakim,我建议您看一下这个示例... https://github.com/seancook/TWReverseAuthExample

Sean is a Twitter employee and i've had no troubles with this code at all. 肖恩(Sean)是推特(Twitter)的一名雇员,我在使用此代码方面没有遇到任何麻烦。 Takes alot of the headaches away and handles errors nicely. 消除了很多麻烦,并很好地处理了错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM