我试图使用LinkedIn配置文件访问数据。
首先,我遵循了。因此,我开始使用Scribe将代码从PHP翻译到Java。
然后,我在Github上找到了一个类似于我所做的例子:https://github.com/fernandezpablo85/TokenExchangeSample/blob/master/src/main/java/com/linkedin/oauth/ExchangeService.java
在授权和cookie交换之后,我得到了这个字符串:
oauth_token=75--4ff2c506-37e2-4b77-927f-c28c5f511762&oauth_token_secret=c73110b2-0dce-43bd-8537-8c8fb4fd5290&oauth_expires_in=5183975&oauth_authorization_expires_in=5183975
在PHP中,列出的代码帮助获取$url中描述的用户数据:
// go to town, fetch the user's profile
$url = 'http://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline)';
$oauth->fetch($url, array(), OAUTH_HTTP_METHOD_GET, array('x-li-format' => 'json')); // JSON!
$profile = json_decode($oauth->getLastResponse());
print "$profile->firstName $profile->lastName is $profile->headline.";因此,代码工作并返回数据。在Java版本中,我想知道如何使用返回的令牌。
我试过用in=5183975
但不起作用。
发布于 2015-04-04 07:03:44
我找到了解决方案:在获得Oauth10a键之后,应该通过指定json格式在新请求中使用它们。
OAuthService service = new ServiceBuilder()
.apiKey(APIKEY)
.apiSecret(SECRETKEY)
.provider(LinkedInApi.class)
.build();
OAuthRequest oAuthRequestData = new OAuthRequest(Verb.GET, DATAENDPOINT);
oAuthRequestData.addHeader("x-li-format", "json");
Token accessToken = new Token(oauth_token, oauth_token_secret);
service.signRequest(accessToken, oAuthRequestData);
Response oAuthResponse = oAuthRequestData.send();
System.outt.println(oAuthResponse.getBody());https://stackoverflow.com/questions/29422293
复制相似问题