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.
I’m trying to follow the guide that twitter posted here: 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?
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?
Or is it a value that should be hashed based on something?
And my POST request currently looks like this:
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
Sean is a Twitter employee and i’ve had no troubles with this code at all. Takes alot of the headaches away and handles errors nicely.