Getting Request Token From Dropbox OAuth “Invalid OAuth Request”

╄→尐↘猪︶ㄣ 提交于 2020-01-17 08:22:47

问题


I'm trying to get a response data from dropbox oauth as described here Now i dont know why it keeps saying {"error": "Invalid OAuth request."}

Here is a my complete code for requesting token:

-(void)requestTokenSecret
{

  NSString* oauthVersion=@"1";
  NSString* oauth_signature_method=@"PLAINTEXT";


  NSString* postHeader = [NSString stringWithFormat: @"Authorization: OAuth oauth_version=\"%@\", oauth_signature_method=\"%@\", oauth_consumer_key=\"%@\", oauth_signature=\"%@&\"",oauthVersion,oauth_signature_method,APP_KEY,APP_SECRET];
  NSLog(@"URL HEADER: %@",postHeader);


  NSData* postHeaderData = [postHeader dataUsingEncoding:NSUTF8StringEncoding]; 

  NSMutableURLRequest* request= [[NSMutableURLRequest alloc]init];

  [request setURL:[NSURL URLWithString:@"https://api.dropbox.com/1/oauth/request_token"]];
  [request setHTTPMethod:@"POST"];

  [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

  [request setValue:[NSString stringWithFormat:@"%d",[postHeaderData length]] forHTTPHeaderField:@"Content-Length"];
  [request setHTTPBody:postHeaderData];

  NSURLConnection* conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
  [conn start];
  if(conn)
  {
    NSLog(@"Connected");
  }
  else
    NSLog(@"Connected");
}

回答1:


It looks like you're putting "Authorization: OAuth ..." in the body of the POST request instead of putting "OAuth ..." in the Authorization header.

Give this code a try instead (untested, sorry):

NSString* oauthVersion=@"1";
NSString* oauth_signature_method=@"PLAINTEXT";

NSString* authorizationHeader = [NSString stringWithFormat: @"OAuth oauth_version=\"%@\", oauth_signature_method=\"%@\", oauth_consumer_key=\"%@\", oauth_signature=\"%@&\"",oauthVersion,oauth_signature_method,APP_KEY,APP_SECRET];

NSMutableURLRequest* request= [[NSMutableURLRequest alloc]init];

[request setURL:[NSURL URLWithString:@"https://api.dropbox.com/1/oauth/request_token"]];
[request setHTTPMethod:@"POST"];

[request setValue:authorizationHeader forHTTPHeaderField:@"Authorization"];

NSURLConnection* conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
[conn start];

Also, I would strongly suggest using OAuth 2 instead of OAuth 1. It's considerably simpler.



来源:https://stackoverflow.com/questions/27917546/getting-request-token-from-dropbox-oauth-invalid-oauth-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!