这是教程Getting Started中的代码,我只是尝试它,没有其他任何东西在运行。
public class Launch {
private static final String url =
"http://api.linkedin.com/v1/people/~/connections:(id,first-name,last-name,email-address,picture-url)";
private static final String url2 =
"http://api.linkedin.com/v1/people/~/connections:(id,first-name,last-name)";
public Launch() {
OAuthService service = new ServiceBuilder()
.provider(LinkedInApi.class)
.apiKey("xxxx")
.apiSecret("xxxx")
.build();
Token requestToken = service.getRequestToken();
String authUrl = service.getAuthorizationUrl(requestToken);
Verifier v = new Verifier("verifier you got from the user");
Token accessToken = service.getAccessToken(requestToken, v); // the requestToken you had from step 2
OAuthRequest request = new OAuthRequest(Verb.GET, url2);
service.signRequest(accessToken, request); // the access token from step 4
Response response = request.send();
System.out.println(response.getBody());
}
在我的控制器中,我有:
@View
public Response.Content index(){
Launch launch = new Launch();
return index.ok();}
当我尝试启动它时,它给了我这个错误:
org.scribe.exceptions.OAuthException:响应正文不正确。无法从中提取令牌和秘密:'oauth_problem = permission_unknown'
答案 0 :(得分:0)
找到解决方案:更改代码以在Scanner in = new Scanner(System.in);
声明后添加ServiceBuilder
以在Verifier verifier = new Verifier(in.nextLine());
另外,手动输入终端中找到的网址System.out.println(service.getAuthorizationUrl(requestToken));
这是一个临时网址,但这是迄今为止唯一有效的方式。