尝试从 facebook 获取 access_token 时,我收到状态码 404。这是一个用 Java 编写的 GAE 应用程序,我正在以编程方式获取 access_token。也就是说,一旦我得到“代码”,我就会发出 https 请求来获取 access_token。我正在使用 restlet.org 框架。
public void getAccessToken( final Map<String,String> filter ) {
//prepare and issue the request. Send in the host and other data
String url = Application.getInstance().getAccessTokenUrl( this.getReference().getHostIdentifier(), filter );
Client client = new Client(Protocol.HTTPS);
client.setConnectTimeout(5000);
Request request = new Request(Method.GET, url);
client.handle(request, new Uniform() {
@Override
public void handle(Request arg0, Response response) {
if ( response.getStatus().isSuccess() ) {
if ( response.isEntityAvailable() ) {
String result = response.getEntityAsText();
String results[] = result.split("&");
String accessTokens[] = results[0].split("=");
filter.put("access_token", accessTokens[1]);
}
} else {
// the user doesn't exist
log.warning("getAccessToken, description - " + response.getStatus().getDescription() + ", code - " + response.getStatus().getCode() + ", all - " + response.getStatus().toString());
setStatus(new Status(Status.CLIENT_ERROR_NOT_FOUND, "Failed to get facebook access code."));
}
}
});
}
其中 code、client_id、client_secret 和 redirectUrl 都结合起来创建正确的 http url。
当我从我的开发环境(192.168.1.../facebook/signin)本地运行它时,这非常有效。但是,当我在 GAE 上运行它时,它会在尝试检索 access_token 时返回 404。我已经记录了 GAE 发送的 http 请求并且它是正确的。也就是说,如果我将请求(https://graph.facebook.com/oauth/access_token?client_id=298631 ... )插入我的浏览器,它会正确返回 access_token。我相信这证实了 Facebook 上的应用程序设置是正确的。
因此,当代码从我的开发系统执行时,它会正确运行,当我将 GAE 在浏览器中发送的 URL 插入时,它会正确运行,只有在 GAE 发送 http 请求时才会失败。
有人对这可能是什么或要寻找什么有任何建议吗?