6 spring-mvc linkedin spring-social-linkedin oltu
我期待开发Spring MVC + Apache Oltu + Linkedin集成示例.在此示例中,您需要发送客户端ID和客户端密钥以从站点中的链接访问私有资源.
第一步 - 我们需要在Linkedin中创建App,请按照以下步骤操作:http://codeboxr.com/how-to-create-linkedin-app.html
创建应用程序后,您需要确保为重定向URL指定了值.
在java代码中我使用了setScope("r_network w_share r_basicprofile")setState("987654321")
当我使用以下代码时:
request= new OAuthBearerClientRequest("https://api.linkedin.com/v1/people/").buildQueryMessage();
Run Code Online (Sandbox Code Playgroud)
我得到以下错误.有人可以吗?
Could not access resource: 401 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
<status>401</status>
<timestamp>1429554559432</timestamp>
<request-id>QJWNLL5PWX</request-id>
<error-code>0</error-code>
<message>Unknown authentication scheme</message>
</error>
Run Code Online (Sandbox Code Playgroud)
重要的是,我在下面得到了正确的详细信息,但似乎访问私人资源:
{"access_token":"SQXZVmVM05AOzDB_DdBm5iaJkrEC8oK-FgE1m1snEZbMcKUODew9I0ZQ6NWc8JtGDxTtEd-yyPul0FtF3-hG4ah6LZ9P4oaSVuhhtybRFmjfsZcJwOs5Lm2IDUGQnjmq5EdT3PVR7Bocq31VBXg0JtkQdImab945oicO_w2j6CjlByp-bWw",
"expires_in":5108376}
Run Code Online (Sandbox Code Playgroud)
您似乎已成功获取OAuth 2.0访问令牌,在进行API调用时,您需要在查询参数中传递access_token.这就是处理OAuth 2.0身份验证的方式(OAuth 1.0要求访问令牌位于标头中,而OAuth 2.0依赖于查询参数).
例如:
获取https://api.linkedin.com/v1/people/~?oauth2_access_token= {your-access-token}
如果需要更多详细信息,请点击链接:https://developer-programs.linkedin.com/forum/unknown-authentication-scheme
如果您发送令牌以及访问受保护资源的请求,那么您应该获得以下详细信息.
更正的代码段:
request= new OAuthBearerClientRequest
("https://api.linkedin.com/v1/people/~?oauth2_access_token="+oAuthResponse.getAccessToken()).
buildQueryMessage();
Run Code Online (Sandbox Code Playgroud)
在我的示例中,我收到以下HTTP 200 OK响应,只是想告诉你..
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<person>
<id>LLIyXMKhNI</id>
<first-name>FirstName</first-name>
<last-name>LastName</last-name>
<headline>Spring Developer at Amazon</headline>
<site-standard-profile-request>
<url>https://www.linkedin.com/profile/view?id=154416688&authType=name&authToken=ipNL&trk=api*a4360331*s4423501*</url>
</site-standard-profile-request>
</person>
Run Code Online (Sandbox Code Playgroud)
希望这会对你有所帮助.
归档时间: |
|
查看次数: |
4496 次 |
最近记录: |