0

我作为制作人与 Oauth 合作。我想要的是当用户从我的系统登录时,如果他/她是授权用户,他/她应该获得访问令牌。身份验证过程将通过请求令牌完成。现在,当我调用 getRequestToken() 时,我的代码出现了问题。由于我的程序已成功连接到我提供的站点名称/ IP 地址,但它在 tomcat7 中执行期间引起了问题。我在这里发布我的代码。

OAuthConfig config;
DefaultApi10a api;

public static void main(String[] args) {
    OAuthService service = new ServiceBuilder().provider(OauthAsServerApi.class)
          .ap Key(nonce).apiSecret(nonce).callback("some IP address").build();

    Token requestToken = service.getRequestToken();

    System.out.println(requestToken.toString());
    Scanner in = new Scanner(System.in);

    Verifier verifier = new Verifier(in.next());

    // Trade the Request Token and Verifier for the Access Token
    Token accessToken = service.getAccessToken(requestToken, verifier);
    OAuthRequest request = new OAuthRequest(Verb.POST,
                PROTECTED_RESOURCE_URI);
    request.addBodyParameter("param", "value");
    service.signRequest(accessToken, request);
    Response response = request.send();
    System.out.println(response.getBody());
    }

当我执行此操作时,我收到以下错误:

Exception in thread "main" org.scribe.exceptions.OAuthException: Response body is incorrect. Can't extract token and secret from this: '<html><head><title>Apache Tomcat/7.0.40 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - /auth/oauth/v1/request</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>/auth/oauth/v1/request</u></p><p><b>description</b> <u>The requested resource is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.40</h3></body></html>'
    at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:41)
    at org.scribe.extractors.TokenExtractorImpl.extract(TokenExtractorImpl.java:27)
    at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:52)
    at com.oauth.OauthAsServer.main(OauthAsServer.java:37)

这里的主要问题是由于tomcat7。它无法使用外部主机名(远程站点)。

谁能帮我解决这个问题??

4

0 回答 0