javascript - Why do I get an "Invalid gadgets.rpc token" error when loading the Google+ JS client? -


i want able make calls google+ in js code such this:

    gapi.client.plus.people.get({"userid": "me"}); 

in html i'm loading following js sources:

    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>     <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=[our maps api key]&sensor=true"></script>     <script type="text/javascript" src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>     <script type="text/javascript" src="biketracker.js"></script>     <script type="text/javascript" src="https://apis.google.com/js/client.js?onload=ongooglejsclientloaded"></script> 

in biketracker.js, i'm doing async load of google+ js:

(function() {     var po = document.createelement('script'); po.type = 'text/javascript'; po.async = true;     po.src = 'https://apis.google.com/js/plusone.js';     var s = document.getelementsbytagname('script')[0]; s.parentnode.insertbefore(po, s); })(); 

the callback when google js client source loaded loads 3 other google apis:

function ongooglejsclientloaded() {     console.log("ongooglejsclientloaded()");      gapi.client.load("biketracker", "v1", onbiketrackerapiloaded, endpointsroot);     gapi.client.load("oauth2", "v2", onoauth2loaded);     gapi.client.load("plus", "v1", ongoogleplusclientloaded); } 

the first of these not google api, google endpoints api we've developed, hosted on app engine. ignore it. oauth2 loads fine. plus api, however, gives me these errors:

invalid gadgets.rpc token. 2006255737 vs 542328210 uncaught error: m`apiproxy6892d048ac55f727a04aed9791f4e586b15e69860.4984859501703547 

i can find no-one else same errors. doing wrong?

are using google+ sign-in, +1 button, or various badges? if not using these features (although should if have social app) not need plusone.js: google client library need api access , if gapi.client defined, should able load google+ client library without issue. test this, can see if gapi.client.plus... exists, , if does, have access google+ endpoints!

if using google+ sign-in, should not performing async load of google api script within own js modules. reasons go beyond scope of answer, of javascript code used javascript google client libraries must initialized globally. second cause of error.

these errors may not causing bugs on site. plusone.js script used render various widgets on screen such google+ sign-in button , culprit rpc errors you're encountering. sometimes, api can fail on first load , ok long button rendering expect.

you might encountering race condition client library or google+ libraries competing each other. try including client.js in addition plusone.js async load function , add callback when scripts load:

<script type="text/javascript"> (function() {   var po = document.createelement('script');   po.type = 'text/javascript'; po.async = true;   po.src = 'https://plus.google.com/js/client:plusone.js?onload=ongooglejsclientloaded';   var s = document.getelementsbytagname('script')[0];   s.parentnode.insertbefore(po, s); })(); 


Comments