我正在编写一个C#应用程序来使用Linkedin的API.
我希望能够照顾"人"(名字+姓氏)并检索有关这一群人的所有可能信息 with the same name
我目前正在使用我自己的REST API实现与People-Search API调用一起使用.
这是我的请求,有效:
https://api.linkedin.com/v1/people-search:(people:(id,first-name,last-name,headline,picture-url),num-results)?
Run Code Online (Sandbox Code Playgroud)
这样做(有:first-name=parameter&last-name=parameter after the ? mark)
问题是,我想要检索更多信息,如:标题,行业,当前公司,当前学校等.请参阅此处的可能参数列表
这种表示法就是他们所说的Field Selectors
我如何构建我的API调用,以便我可以获得有关某人的所有可能信息?
当且仅当用户在发出OAuth2请求时登录LinkedIn时,它才有效.
如果用户未登录,则会遇到错误.
我们行动的顺序:
https://api.linkedin.com/v1/people/\~在此之后,我们收到401以下内容:
{
"errorCode": 0,
"message": "Unable to verify access token",
"requestId": "C0DUCX81SA",
"status": 401,
"timestamp": 1421946470523
}
Run Code Online (Sandbox Code Playgroud)
有时,经过一段时间后,使用相同的访问令牌重试会产生200.有时不会.
如果用户在此"401周期"期间登录到LinkedIn,则神奇地以前获取的访问令牌开始工作.
我不知道如何解决这个问题,因为它似乎是LinkedIn的一个问题.
有人有任何建议或者之前有人看过这种行为吗?
我们尝试过cookie设置,在请求之前等待一段时间.
我们正在向Zotonic [1]添加LinkedIn OAuth2身份验证,但现在仍然使用非工作模块.
编辑:
有人提到LinkedIn的两个讨论.他的答复现在遗憾地从下面的讨论中消失了.
这些是链接:
https://developer.linkedin.com/forum/unable-verify-access-token
我在这些讨论中尝试了所有建议,但无济于事.
编辑#2:
检查LinkedIn上的第一个讨论表明我并不是唯一一个遇到这些一致性问题的人.如果用户已经清除了cookie或者在OAuth"舞蹈"期间必须登录LinkedIn,那么在LinkedIn上会出现问题 https://developer.linkedin.com/forum/unable-verify-access-token#comment-36950
更新
解决了,感谢Matthijs Bierman,请看下面的答案.
嗨,在我的servlet代码中,我代表用户请求具有access_token的服务器,我可以使用以下代码请求:
OAuthRequest request2 = new OAuthRequest(Verb.GET,"https://api.linkedin.com/v1/people/~:(first-name,last-name,email-address)?oauth2_access_token="+accesstok);
Run Code Online (Sandbox Code Playgroud)
但我如何使用如下的授权标头请求:
GET /v1/people/~ HTTP/1.1
Host: api.linkedin.com
Connection: Keep-Alive
Authorization: Bearer AQXdSP_W41_UPs5ioT_t8HESyODB4FqbkJ8LrV_5mff4gPODzOYR
Run Code Online (Sandbox Code Playgroud)
我使用以下方式,但不是wrking:
private static final String PROTECTED_RESOURCE_URL = "/v1/people/~:(first-name,last- name,email-address) HTTP/1.1 Host: api.linkedin.com Connection: Keep-Alive Authorization: Bearer ";
Object AccessToken= o.get("access_token");
String accesstok=AccessToken.toString();
OAuthRequest request2 = new OAuthRequest(Verb.GET,PROTECTED_RESOURCE_URL+accesstok);
Run Code Online (Sandbox Code Playgroud)
谢谢