【发布时间】:2026-02-08 20:45:01
【问题描述】:
转发:
目标:
我正在使用 GWT 并尝试使用 RestyGWT 客户端调用现有的 Twitter REST 服务
问题:
我没有收到对“https://api.twitter.com/1.1/statuses/mentions_timeline.json”或其他 json 的 GET 请求的响应。
我尝试过的事情:
我查看了 RestyGWT 的文档,但找不到关于如何调用第三方 REST 服务的具体示例。尝试使用纯文本返回类型调用 REST 服务,同样的问题。从根本上说,我一定是做错了什么。
代码:
这是我的 onModuleLoad:
public void onModuleLoad() {
Resource r = new Resource("https://api.twitter.com/1.1/statuses/mentions_timeline.json");
r.get().send(new JsonCallback() {
@Override
public void onSuccess(Method method, JSONValue response) {
System.out.println("Twitter response:\tYES");
}
@Override
public void onFailure(Method method, Throwable exception) {
System.out.println("Twitter response:\tNO");
System.out.println("Exception:\t\t"+exception.toString());
System.out.println("Exception Message:\t"+exception.getMessage());
System.out.println("Status code:\t\t"+method.getResponse().getStatusCode() );
}
});}
输出:
GWT MODULE LOADED
Twitter response: NO
Exception: org.fusesource.restygwt.client.FailedStatusCodeException:
Exception Message:
Status code: 0
【问题讨论】:
-
您正在尝试进行跨站点请求,首先查看crazygui.wordpress.com/2012/08/08/… 可能还有groups.google.com/forum/#!searchin/restygwt/csrf/restygwt/… 然后您需要对此调用进行身份验证。如果未通过身份验证,您应该会收到 215 错误。