requireJS and Google+ Javascript API -


i have been trying while , totally stuck on issue , hope can give me ideas how can solve this. problem here.

i use google javascript api site login. javascript is

define(function (require) {     init = function(){         require( ['https://apis.google.com/js/platform.js?onload=renderbutton'], function(gapi){             renderbutton();         });     },     renderbutton = function(){         console.log("renderbutton called");         gapi.signin2.render('google-signin', {             'scope': 'https://www.googleapis.com/auth/plus.login',             'width': 151,             'height': 25,             'longtitle': true,             'theme': 'dark'         });     }, }); 

when this, returns error message "referenceerror: gapi not defined"

so have tried below no luck.

define(function (require) {     init = function(){         require( ['https://apis.google.com/js/platform.js?onload=renderbutton'], function(gapi){             renderbutton(gapi);         });     },     renderbutton = function(gapi){         console.log("renderbutton called");         gapi.signin2.render('google-signin', {             'scope': 'https://www.googleapis.com/auth/plus.login',             'width': 151,             'height': 25,             'longtitle': true,             'theme': 'dark'         });     }, }); 

i set requirejs config this:

window.require = {     "shim": {         "gapi": {             "exports": "gapi"         }     },     "paths": {         "gapi": "https://apis.google.com/js/platform"     } } 

then can do:

require(['gapi'], function (gapi) {   gapi.load("", function () {     // ..whatever..   }); }); 

it's...a weird library though. trying signing library , ended needing this

gapi.load('auth2', function () {   gapi.auth2.init({     client_id: google_sign_in_client_id   });   gapi.load('signin2', function () {     gapi.signin2.render('g-signin', options);   }); }); 

so may want set 'google-signin' loader. requirejs loader plugins. this:

define('gapi', {     load: function (name, req, onload, config) {         //req has same api require().         req(['gapi'], function (gapi) {             gapi.load(name, function () {               onload(gapi[name]);            });         });     } }); 

and can just:

require(['gapi!auth2', 'gapi!signin2'], function (auth2, signin2) {   auth2.init({client_id: clientid});   signin2.render(...); }); 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -