Linkedin API错误iPhone入门套件中的无效签名



我尝试开箱即用地运行OAuthStarterKit xcode项目,输入了正确的api密钥/secret和oauth用户令牌/secret。当我用这个代码授权时:

    OAMutableURLRequest *request = 
        [[[OAMutableURLRequest alloc] initWithURL:requestTokenURL
                                         consumer: self.consumer
                                            token: self.requestToken   
                                         callback:linkedInCallbackURL
                                signatureProvider:sha] autorelease];

它返回错误"signature_invalid",这似乎表明签名不正确。明文和secret混合了大小写字符,我不确定这会有什么不同。

如果我使用

requestTokenURLString = @"https://api.linkedin.com/uas/oauth/requestToken?scope=r_basicprofile+r_emailaddress";

它返回无效的sig。。。但是如果我使用基本权限调用

requestTokenURLString = @"https://api.linkedin.com/uas/oauth/requestToken;

它工作得很好,但这意味着我只有基本的配置文件权限,在那里我需要电子邮件地址之类的东西。

在测试控制台中输入所有相同的数据似乎在这里工作得很好:

https://developer.linkedin.com/oauth-test-console

有人知道我应该做什么、想什么,或者我应该去哪里看吗?进一步的日志信息:

oauth_problem=signature_invalid
oauth_problem_advice=com.linkedin.security.auth.pub.LoginDeniedInvalidAuthTokenException while obtaining request token for: POST https://api.linkedin.com/uas/oauth/requestToken/oauth_callback:hdlinked://linkedin/oauth 
oauth_consumer_key: XXX
oauth_nonce
oauth_signature_method: 3DHMACSHA1
2012-09-04 23:36:07.054 OAuthStarterKit[31952:c07] secret: TIDi9XXXXXXX
2012-09-04 23:36:07.054 OAuthStarterKit[31952:c07] base64EncodedResult: JXW6ZWUpXv7ba98o2hcUXodDhmg=

我正在使用这里的代码示例https://github.com/synedra/LinkedIn-OAuth-Sample-Client

编辑:明天我会努力弄清真相,如果没有人能打败我,我会回答我自己的问题。

在与Linkedin API Beast争论了很多之后,我发现问题出在OAuthLoginView.m中方法'requestTokenFromProvider'中的编码方式上,这是一个很长的故事。我需要在OARequestParameter对象中包含具有相关权限的参数'scope'。

(基于github回购->https://github.com/synedra/LinkedIn-OAuth-Sample-Client)

之后,无论你在哪里进行api调用,(例如在OAuthStarterKit中)就像在ProfileTabView::profileApiCall中一样,你都可以发出这样的URL帖子:http://api.linkedin.com/v1/people/~:(id,名字,姓氏,行业)"];或者,如果你需要他们的电子邮件地址,它就会出现(只要你有访问电子邮件的权限,你也可以简单地获取:

NSURL *url = [NSURL URLWithString:@"http://api.linkedin.com/v1/people/~:(id,first-name,last-name,industry,email-address)"];

请参阅下面的URL请求中使用OARequestParameter的代码。。。

- (void)requestTokenFromProvider
{
    OAMutableURLRequest *request = 
            [[[OAMutableURLRequest alloc] initWithURL:requestTokenURL
                                             consumer:self.consumer
                                                token:nil   
                                             callback:linkedInCallbackURL
                                    signatureProvider:nil] autorelease];
    [request setHTTPMethod:@"POST"];
    OARequestParameter * scopeParameter=[OARequestParameter requestParameter:@"scope" value:@"r_fullprofile r_contactinfo r_emailaddress"];
    [request setParameters:[NSArray arrayWithObject:scopeParameter]];
    OADataFetcher *fetcher = [[[OADataFetcher alloc] init] autorelease];
    [fetcher fetchDataWithRequest:request
                         delegate:self
                didFinishSelector:@selector(requestTokenResult:didFinish:)
                  didFailSelector:@selector(requestTokenResult:didFail:)];    
}

为了更深入地使用linkedin的API,我将在我的博客上保留一些快速提示->http://techrantnz.blogspot.com.au/2012/09/the-linkedin-api-with-oauthstarterkit.html

如果你想检查事情是否正常,请检查如果成功则调用的方法

- (void)profileApiCallResult:(OAServiceTicket *)ticket didFinish:(NSData *)data

如果你输出响应体,你可能会看到这样的东西:

2012-09-05 21:40:55.109 OAuthStarterKit[12244:c07] profile: {
    emailAddress = "[my email]@gmail.com";
    firstName = Dave;
    id = XXXXXX;
    industry = "Information Technology and Services";
    lastName = "XXXXXXXX";
}

最新更新