0

我试图从retrieveRequestToken 路标API 获取Auth_url。它抛出 OAuthCommunicationException。当我对 twitter 使用相同的代码时(在更改消费者和提供之后),它可以正常工作。请在这里帮助我。谢谢

public class NetflixTest {

private static final long serialVersionUID = 1L;

    public static final String NETFLIX_REQUEST_TOKEN_URL = "http://api.netflix.com/oauth/request_token";
    public static final String NETFLIX_ACCESS_TOKEN_URL = "http://api.netflix.com/oauth/access_token";
    public static final String NETFLIX_AUTHORIZE_URL = "https://api-user.netflix.com/oauth/login";

    public static void main(String[] args) {

        System.setProperty("debug", "1");
        OAuthConsumer consumer = new DefaultOAuthConsumer("jw5pvuq766d6rf4m2pu2ft5r", "y8x3dhMFqz");    
        OAuthProvider provider = new DefaultOAuthProvider(NETFLIX_REQUEST_TOKEN_URL,
            NETFLIX_ACCESS_TOKEN_URL, NETFLIX_AUTHORIZE_URL);

        try {
            String authUrl = provider.retrieveRequestToken(consumer, "http://mydomain.com/Netflix/");       
            System.out.println(authUrl);

        } catch (OAuthMessageSignerException e) {
            e.printStackTrace();
        } catch (OAuthNotAuthorizedException e) {
            e.printStackTrace();
        } catch (OAuthExpectationFailedException e) {
            e.printStackTrace();
        } catch (OAuthCommunicationException e) {
            e.printStackTrace();
            System.out.println(e.getResponseBody());
        }

    }
}
4

1 回答 1

0
    if (connection.getRequestMethod().equalsIgnoreCase("POST")) {
        connection.setRequestProperty("Content-Type",
                "application/x-www-form-urlencoded");
        connection.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(
                connection.getOutputStream());
        wr.writeBytes("");
        wr.flush();
        wr.close();
    } else {
        connection.connect();
    }

如上所述更改了 DefaultOAuthProvider 类的 sendRequest。似乎服务器很严格,并且在您执行 POST 时需要一些字节。

于 2011-02-03T20:09:33.313 回答