Search code examples
twitterhttp-postxauth

How to make Twitter XAuth post request data for access token?


When I had used following code, I got the message "Failed to validate oauth signature and token"

     NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"]];
  [request setHTTPMethod:@"POST"];

  NSString *postString = @"oauth_consumer_key=My Consumer key&oauth_signature_method=HMAC-SHA1&oauth_signature=My Consumer secret&oauth_timestamp=?????&oauth_nonce=?????oauth_version=1.0&x_auth_username=My Twitter ID&x_auth_password=My Twitter password&x_auth_mode=client_auth";
  [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; 

  NSHTTPURLResponse *response = NULL;
  NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
  NSString *responseDataString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];

  NSLog(@"Response from Twitter: %@", responseDataString);

So, I want to know exact configuration of request contents The used post data as following. and My application had the ability to use xAuth

oauth_consumer_key=My Consumer key

oauth_signature_method=HMAC-SHA1

oauth_signature=My Consumer secret

oauth_timestamp=?????

oauth_nonce=?????

oauth_version=1.0

x_auth_username=My Twitter ID

x_auth_password=My Twitter password

x_auth_mode=client_auth


Solution

  • Read this. Hope it will help you. https://dev.twitter.com/docs/oauth/xauth