FB.getLoginStatus(function(response) {
if (response.status === 'connected')
// DO SOMETHING
});@JsType(isNative = true)
public static interface FB {
void init(FBParamObj fbParamObj);
void getLoginStatus(CustomCallbackFunction callbackFunction);
}
However, I'm not sure how to define the CustomCallbackFunction callbackFunction that I need to provide as a parameter to FB.getLoginStatus. FB.getLoginStatus is provided by the Facebook SDK so I can not change it.
How do I create this JavaScript callback function in GWT so I can pass it to the FB SDK as a parameter?
I'm sure I'm missing something very basic but I can't seem to find it in the documentation.
Thank you for the help!
Tony
@JsType(isNative = true)
private static class FbResponse {
private String status;
private FbAuthResponse authResponse;
}
@JsType(isNative = true)
private static class FbAuthResponse {
private String accessToken;
private Integer expiresIn;
private String userID;
}
@JsType(isNative = true)
private static interface FB {
void init(FBParamObj fbParamObj);
void getLoginStatus(FbLoginStatusCallbackJsFunction fbLoginStatusCallbackJsFunction);
}
@JsProperty(namespace = JsPackage.GLOBAL)
private static native FB getFB();
private static class FBParamObj {
@JsProperty
String appId = ApplicationClientConstants.FacebookAppID;
@JsProperty
String version = ApplicationClientConstants.FacebookAuthSDKVer;
@JsProperty
boolean cookie = true;
@JsProperty
boolean xfbml = false;
}
@JsMethod(namespace = JsPackage.GLOBAL)
public static final void fbAsyncInit() {
getFB().init(new FBParamObj());
getFB().getLoginStatus(new FbLoginStatusCallbackJsFunction() {
@Override
public JavaScriptObject call(FbResponse response) {
Window.alert(" status: " + response.status + //
"\n userID: " + response.authResponse.userID + //
"\n accessToken: " + response.authResponse.accessToken + //
"\n expiresIn: " + response.authResponse.expiresIn);
return null;
}
});
}
@JsFunction
private interface FbLoginStatusCallbackJsFunction {
public JavaScriptObject call(FbResponse response);
}