RestyGWT 和 GWT 集成:无法获取资源



目标:

我正在使用GWT,并尝试使用RestyGWT客户端调用现有的Twitter REST服务

问题:

我没有收到对"https://api.twitter.com/1.1/statuses/mentions_timeline.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:tt"+exception.toString());
                    System.out.println("Exception Message:t"+exception.getMessage());
                    System.out.println("Status code:tt"+method.getResponse().getStatusCode() );
                    }
            });
}

输出:

GWT MODULE LOADED
Twitter response:   NO
Exception:          org.fusesource.restygwt.client.FailedStatusCodeException: 
Exception Message:  
Status code:        0

如果您正在访问不属于您的远程服务,则通常必须发送 JSONP 请求才能使用同一源策略。所以试试r.jsonp()而不是r.get()

jsonp 至少调用服务方法,但状态代码为 0 的异常。但是,get甚至没有到达服务方法。

最新更新