Skip to content

Instantly share code, notes, and snippets.

@ochilab
Created June 18, 2013 08:28
Show Gist options
  • Save ochilab/5803605 to your computer and use it in GitHub Desktop.
Save ochilab/5803605 to your computer and use it in GitHub Desktop.
GWTでJSONPを利用するサンプル。Twitterを例にしていますが、今は無効です。
String url = "https://api.twitter.com/1/trends/23424856.json"; //このURLは現在無効です
JsonpRequestBuilder jsonp = new JsonpRequestBuilder();
jsonp.requestObject(url, new AsyncCallback<JsArray<Feed>>() {
@Override
public void onFailure(Throwable caught) {
// TODO エラー処理
}
@Override
public void onSuccess(JsArray<Feed> result) {
System.out.println("SUCCESS:"+result.length());
JsArray<User> users = result.get(0).getTrends();
for(int i=0; i<users.length(); i++) {
System.out.println(i+": "+users.get(i).getName());
}
}
});
package org.ochilab.jsonp.client;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
class Feed extends JavaScriptObject {
protected Feed() {}
public final native JsArray<User> getTrends() /*-{
return this.trends;
}-*/;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment