使用的请求令牌未经用户授权

时间:2014-09-21 02:02:16

标签: c# spring api linkedin

我有一个应用程序,其中包含有关在LinkedIn上注册的一些公司的信息。工人罚款超过6个月,但几天前它开始崩溃。原因是现在LinkedIn API并不认为它通过请求“https://api.linkedin.com/uas/oauth/requestToken”提供的访问令牌是有效的。我正在使用 Spring.Social.LinkedIn 库来获取有关公司的信息。那么,这就是我在代码中所做的: 的授权

      OAuthLinkedIn _oauth = new OAuthLinkedIn();
      string _linkedInUserToken = _oauth.GetRequestToken();
      string _linkedInUserSecret = _oauth.TokenSecret;
      var provider = new LinkedInServiceProvider(_linkedInApiKey, _linkedInApiSecret); -> here I set keys provided for my application by LinkedIn
      ILinkedIn _api = provider.GetApi(_linkedInUserToken, _linkedInUserSecret);

然后我想了解一些公司的信息:

Task<string> task = _api.ProfileOperations.GetCompanyByNameAsync(companyName);
string resJson = task.Result;

在最后一行我得到例外,说我没有被授权。 以下是访问令牌的请求:

POST https://api.linkedin.com/uas/oauth/requestToken HTTP/1.1
User-Agent: YourAgent
Content-Type: application/x-www-form-urlencoded
Host: api.linkedin.com
Content-Length: 221
Connection: Keep-Alive

oauth_callback=liconnect%3A%2F%2Fsuccess&oauth_consumer_key=**%MY_KEY%**&oauth_nonce=4201230&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1411263546&oauth_version=1.0&oauth_signature=P8GrtPq54XFdiu6HNFaWbQAND%2bc%3d

回复是:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/plain
Content-Length: 240
Vary: Accept-Encoding
Date: Sun, 21 Sep 2014 01:39:06 GMT
X-FS-UUID: 923111eab7d09513c0dbcaee602b0000
X-LI-UUID: kjER6rfQlRPA28ruYCsAAA==
X-Li-Fabric: prod-lva1
Connection: keep-alive
X-Li-Pop: PROD-ELA4
Set-Cookie: lidc="b=VB89:g=115:u=1:i=1411263546:t=1411349946:s=4243386344"; Expires=Mon, 22 Sep 2014 01:39:06 GMT; domain=.linkedin.com; Path=/

oauth_token=77--99160ec7-e43f-49ea-916c-c040a882e32b&oauth_token_secret=62e5d39c-8f2a-4908-8114-eb255af3a01b&oauth_callback_confirmed=true&xoauth_request

所以看起来很好。然后我试图获取有关公司的信息。请求是:

GET https://api.linkedin.com/v1/companies/universal-name=valtech:(id,name,employee-count-range,num-followers,locations)?format=json HTTP/1.1
Accept: text/plain,*/*
Authorization: OAuth oauth_consumer_key="**%MY_KEY%**", oauth_signature_method="HMAC-SHA1",     oauth_timestamp="1411263578", oauth_nonce="1543633253", oauth_version="1.0", oauth_token="77--99160ec7-e43f-49ea-916c-c040a882e32b", oauth_signature="bX1A1Fu%2BRvT%2BvtDzgMwrWIqIGM4%3D"
Host: api.linkedin.com

响应是:

HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
x-li-request-id: 5FAMIVKA07
X-LI-UUID: 9KsRaL/QlRNQ6HB4bisAAA==
Date: Sun, 21 Sep 2014 01:39:38 GMT
Vary: *
x-li-format: json
Content-Type: application/json;charset=UTF-8
Content-Length: 183
X-Li-Fabric: prod-lva1
Connection: keep-alive
X-Li-Pop: PROD-ELA4
Set-Cookie: lidc="b=VB89:g=115:u=1:i=1411263578:t=1411349978:s=778497258"; Expires=Mon, 22 Sep 2014 01:39:38 GMT; domain=.linkedin.com; Path=/

{
  "errorCode": 0,
  "message": "[unauthorized]. The request token used hasn't been authorized by user.",
  "requestId": "5FAMIVKA07",
  "status": 401,
  "timestamp": 1411263578909
}

它困惑了我:(这段代码工作了很长时间,但现在它失败了:(我试图找到一些关于此类错误的类似帖子,但我不能。有任何想法如何解决这个问题?谢谢

0 个答案:

没有答案
相关问题