0
我正在使用google api在我的应用程序中执行google lattitude操作。我已完成,直到使用凭据验证用户。现在我试图使用初始请求生成的autherization_code生成accesstoken。但它在didReceiveData函数中通过invalid_request作为错误。可以请你们中的一些人建议我解决我的问题。 Oauth请求格式假设如下。ios invalid_request使用oauth调用身份验证令牌时使用
POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded
code=4/v6xr77ewYqhvHSyW6UJ1w7jKwAzu&
client_id=8819981768.apps.googleusercontent.com&
client_secret={client_secret}&
redirect_uri=https://oauth2-login-demo.appspot.com/code&
grant_type=authorization_code
我IOS代码以执行上述服务calll是如下
NSString * urlString = [NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/token?code=%@&client_id=363756608022.apps.googleusercontent.com&client_secret=dury2bxloSVQ1sdJjg9MKO9s&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code",[userDefaults valueForKey:@"accessTokenResponse"]];
NSURL * url = [NSURL URLWithString:urlString];
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:url];
[request addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod:@"POST"];
NSLog(@"sendng req : %@",request);
NSURLConnection * connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
[connection start];