【问题标题】:Linkedin API Error Invalid Signature in iPhone Starter KitiPhone Starter Kit 中的 Linkedin API 错误签名无效
【发布时间】:2012-08-29 04:54:46
【问题描述】:

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

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

它返回错误“signature_invalid”,这似乎表明签名不正确。明文和秘密混合了大小写字符,我不确定这会有所不同。

如果我使用

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

它返回无效的信号...但如果我使用基本权限调用

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

编辑:如果没有人能打败我,明天我会努力追根究底并回答我自己的问题。

【问题讨论】:

    标签: iphone api oauth linkedin hmac


    【解决方案1】:

    在与 Linkedin API Beast 争论不休后,我发现问题出在编码方式上,说来话长,在 OAuthLoginView.m 中的方法“requestTokenFromProvider”中,我需要将参数“范围”与相关OARequestParameter 对象中的权限。

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

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

    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";
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-23
      • 1970-01-01
      • 2016-10-02
      • 1970-01-01
      相关资源
      最近更新 更多