All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.tomgrill.gdxfacebook.html.JSNIFacebookSDK Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright 2015 See AUTHORS file.
 * 

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ******************************************************************************/ package de.tomgrill.gdxfacebook.html; class JSNIFacebookSDK { static native void FBapi(String graph, String method, String fields, JsonCallback callback) /*-{ // console.log(fields); $wnd.FB.api('/' + graph, method, eval('({' + fields + '})'), function(response) { if (!response || response.error) { console.log("Error occurred: "); console.log(response); [email protected]::error()(); } else { console.log(response); [email protected]::jsonResult(Ljava/lang/String;)(JSON.stringify(response)); } }); }-*/; static native void FBLoginState(StatusCallback callback) /*-{ $wnd.FB.getLoginStatus(function(response) { console.log(response); if (response.status === 'connected') { [email protected]::connected(Ljava/lang/String; Ljava/lang/String;)(response.authResponse.accessToken, response.authResponse.expiresIn); } else if (response.status === 'not_authorized') { [email protected]::notAuthorized()(); } else { // The person is not logged into Facebook, so we're not sure if they are logged into this app or not. [email protected]::disconnected()(); } }); }-*/; static native void FBLogin(String permissions, LoginCallback callback) /*-{ $wnd.FB.login(function(response) { // console.log(response); if (response.authResponse) { [email protected]::success(Ljava/lang/String; Ljava/lang/String; Ljava/lang/String;)(response.authResponse.accessToken, response.authResponse.expiresIn, response.authResponse.grantedScopes); } else { [email protected]::fail()(); } // console.log("login finished with " + permissions); }, {scope: permissions, return_scopes: true}); }-*/; /** * Nearly the same setup as recommend by the quick start guide: * https://developers.facebook.com/docs/javascript/quickstart *

* Notice: Usage of $wnd and $doc */ static native void initSDK(String appIdNr, String apiVersion, InitCallback callback) /*-{ $wnd.fbAsyncInit = function() { $wnd.FB.init({ appId : appIdNr, cookie : true, xfbml : false, version : apiVersion, }); [email protected]::loaded()(); }; // Load the SDK asynchronously (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk/debug.js"; fjs.parentNode.insertBefore(js, fjs); }($doc, 'script', 'facebook-jssdk')); return true; }-*/; }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy