我试图从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());
}
}
}
答案 0 :(得分: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时需要一些字节。