开发者

Issue with OAuth using signpost API on Netflix - OAuthCommunicationException

I tried to get Auth_url from retrieveRequestToken signpost API. It throws OAuthCommunicationException. When I used the same code for twitter(after changing consumer and provide), it works without issue. Please help me here. Thanks

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) {
      开发者_JAVA技巧      e.printStackTrace();
        } catch (OAuthCommunicationException e) {
            e.printStackTrace();
            System.out.println(e.getResponseBody());
        }

    }
}


    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();
    }

Changed sendRequest of DefaultOAuthProvider class as above. Seems like server is strict and expects some bytes when you do POST.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜