在IOS中查询Google请求令牌时,来自oAuth的Signature_invalid错误

时间:2011-05-30 06:00:11

标签: ios oauth

我正在使用oAuth获取谷歌“纬度”范围的未注册已安装应用的请求令牌,我收到的响应字符串为

signature_invalid
base_string:GET&https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthGetRequestToken&oauth_consumer_key%3Danonymous%26oauth_nonce%3D1D759072-DB2B-4E21-AA23-67CADF98C14A%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1306734462%26oauth_version%3D1.0%26scope%3Dhttps%253A%252F%252Fwww.googleapis.com%252Fauth%252Flatitude%26xoauth_displayname%3DTaj%2520Vivanta

我用来获取请求令牌的代码如下

    OAConsumer *consumer = [[OAConsumer alloc] initWithKey:@"anonymous" secret:@"anonymous"]; 
    OAMutableURLRequest *request = [[[OAMutableURLRequest alloc] initWithURL:url consumer: consumer token:token realm:nil signatureProvider: nil] autorelease];
    if (!request) return;
    [request setOAuthParameterName:@"scope" withValue:[@"https://www.googleapis.com/auth/latitude" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    [request setOAuthParameterName:@"xoauth_displayname" withValue:@"Taj Vivanta"];
    [request setHTTPMethod: @"GET"];
    OADataFetcher *fetcher = [[[OADataFetcher alloc] init] autorelease];    
    [fetcher fetchDataWithRequest: request delegate: self didFinishSelector: success didFailSelector: fail];

请帮我解决这个问题,谢谢

1 个答案:

答案 0 :(得分:0)

正如Google Document明确建议的那样,范围和xoauth_displayname参数应该在URL中,但在上面的代码中,我将这些参数放在请求标头中。