gapi.auth.authorize failing

8,200 views
Skip to first unread message

Mike Baker

unread,
Jan 6, 2012, 1:48:01 PM1/6/12
to Google API JavaScript Client
I'm new to trying the JS client library and getting stuck on the call
to gapi.auth.authorize. The code snippet is

init: function() {
gapi.auth.init(GPAS.checkAuth);
}
checkAuth: function() {

gapi.auth.authorize({'client_id':'NNNNNNNN.apps.googleusercontent.com',
'scope':'https://www.googleapis.com/auth/plus.me', 'immediate': true,
'response_type':'token'}, GPAS.handleAuthResult);
}
handleAuthResult: function(resp) {
alert("made it!");
}
The callback function never gets called and Firebug reports an error
GP_Vf is null. The JS that contains the error is obfuscated so I can't
tell what the problem is.

...function GP_Wf(){for(var a=0,b=GP_Vf.length;a<b;a++)GP_Vf[a]
();GP_Vf=GP_}...

Anyone else run into an error like this?

The workflow includes starting up Firefox, logging into Google+, then
launching my test app in a new tab of the same window. The test app
uses one function to call I use this same workflow with another oAuth2
app.

TIA,
Mike

Brendan

unread,
Jan 6, 2012, 2:06:40 PM1/6/12
to Google API JavaScript Client
Can you try authorizing with 'immediate': false (the default if you
omit the immediate param)? The first call can't be immediate since it
requires explicit user authorization. Subsequent calls (to refresh the
auth token which expires in one hour) can be 'immediate': true.

HTH,
Brendan

Mike Baker

unread,
Jan 6, 2012, 3:38:43 PM1/6/12
to Google API JavaScript Client
Is there a delay in reply posting? I sent a reply but I don't see it
here.

I got the same result with 'immediate': false or true when using that
workflow. However I saw other samples that did not use the
gapi.auth.init function so I tried just going straight to checkAuth
and I got a popup with an "origin_mismatch" error. Could it be that
this origin_mismatch is related to the GP_Vf being null when I used
the init function? In what cases is the init function required? Do you
need more info from the error page?

Mike

Mike Baker

unread,
Jan 6, 2012, 2:30:55 PM1/6/12
to Google API JavaScript Client
Same result when using the same workflow and 'immediate': false.
However I saw another sample that used 'gapi.auth.authorize' without
using the 'gapi.auth.init' function first. So I tried that and I wound
up with a popup that said "origin_mismatch". Any chance these two
items are related? Is the 'init' function required or not? Could the
origin_mismatch have caused the GP_Vf problem?

Mike

On Jan 6, 1:06 pm, Brendan <obr...@google.com> wrote:

Brendan

unread,
Jan 6, 2012, 4:24:18 PM1/6/12
to Google API JavaScript Client
Yes, your posts are moderated so I have to approve them. I've added
you to the whitelist, so in the future your posts should show up
immediately.

I believe what's happening is that the callback method to
gapi.auth.init is not optional (this is a bug). Try adding a dummy
callback as a workaround:

gapi.auth.init(function() {})

As for origin_mismatch, check your origins for your client ID. See
this section of the guide:
http://code.google.com/p/google-api-javascript-client/wiki/Authentication#Get_Your_Client_ID

Brendan

Mike Baker

unread,
Jan 6, 2012, 5:09:17 PM1/6/12
to Google API JavaScript Client
When I did use the gapi.auth.init function I did have a callback and
that part worked. My init called init with the callback of
GPAS.checkAuth and the checkAuth had a callback of
GPAS.handleAuthResult(resp). The init call worked fine and the
GPAS.checkAuth was called, but then the call to gapi.auth.authorize
failed and the final function handleAuthResult was not called. When
you suggested trying immediate: false, I tried that first with the
init function in place. That failed so I also tried skipping the init
function and got the origin_mismatch.

Mike


On Jan 6, 3:24 pm, Brendan <obr...@google.com> wrote:
> Yes, your posts are moderated so I have to approve them. I've added
> you to the whitelist, so in the future your posts should show up
> immediately.
>
> I believe what's happening is that the callback method to
> gapi.auth.init is not optional (this is a bug). Try adding a dummy
> callback as a workaround:
>
> gapi.auth.init(function() {})
>
> As for origin_mismatch, check your origins for your client ID. See
> this section of the guide:http://code.google.com/p/google-api-javascript-client/wiki/Authentica...

Brendan

unread,
Jan 6, 2012, 6:11:19 PM1/6/12
to Google API JavaScript Client
Sorry I did not read your first post closely enough. I debugged and
found the issue, which I will fix soon. In the meantime, there is a
workaround. Use setTimeout to make your gapi.auth.authorize call in
checkAuth:

function init() {
gapi.auth.init(checkAuth);
}

function checkAuth() {
setTimeout(function() {
gapi.auth.authorize({
'client_id':'XXXXXXXX.apps.googleusercontent.com',
'scope':'https://www.googleapis.com/auth/plus.me',
'response_type':'token'
}, handleAuthResult);
}, 1);
}

function handleAuthResult(resp) {
alert("made it!");
}

Thanks for reporting this issue.

How about the origin_mismatch? Did you verify the origins for your
client ID are set properly?

Brendan

Mike Baker

unread,
Jan 6, 2012, 8:30:11 PM1/6/12
to Google API JavaScript Client
Thanks Bredan, the app works now with the setTimeout function used to
delay the gapi.auth.authorize function.
I went and checked the origins and I can report another issue. We used
the http://domainName.com format and I wound up having to add the
http://www.domainName.com. Our DNS registry entries allow for either
format to get to the same site so it might be considered a bug that
the format requires the www. The page that describes the procedure
leaves the www off of the domain for JS origins. Since we want to be
covered I'm guessing the correct set of entries would include and
exclude the www for both http and https protocols. Perhaps an update
to the documentation would be sufficient.

Thanks again,
Mike

Tommy Knowlton

unread,
Jan 12, 2012, 3:04:22 PM1/12/12
to google-api-jav...@googlegroups.com
Brendan, I was getting
TypeError: 'null' is not an object (evaluating 'GP_Wf.length')

on line 168 of the obfuscated script found at plus.google.com (sorry, I am hoping this is sufficient locator to be helpful to you),
That was as of this morning; the workaround you recommended for Mike worked also for me.

Please disregard if this doesn't add useful information to the conversation. I'm just posting in case it'd be helpful to you.

Thanks.

Lindsey Simon

unread,
Feb 21, 2012, 2:51:54 AM2/21/12
to google-api-jav...@googlegroups.com
Me too - I just spent some pain time debugging this, and turns out the setTimeout fixes it for me as well.
Thanks for groups!

jaffar....@rolustech.com

unread,
Jan 18, 2013, 8:15:04 AM1/18/13
to google-api-jav...@googlegroups.com
My issue is slightly different everything is ok but popup is not closing and if user allows or disallow

i am using this code in chrome extension
handleClientLoad = function () {
    gapi.client.setApiKey(myapiKey);
    window.setTimeout(checkAuth, 1);
}
checkAuth = function () {
    gapi.auth.authorize({
        client_id: myclientId,
        immediate: true
    }, handleAuthResult);
}

handleAuthResult = function (authResult) {

    var authorizeButton = document.getElementById('authorize-button');
    if (authResult && !authResult.error) {
        // start app
    } else {
        authorizeButton.onclick = handleAuthClick;
    }
}

handleAuthClick = function (event) {
    gapi.auth.authorize({
        client_id: myclientId,
        immediate: false
    }, handleAuthResult);
    return false;
}

please help me to get rid of this and in worst case user has to mannually close popup and refresh parent window from where popup shown to get start using my app

Jaffar Hussain

unread,
Jan 29, 2013, 11:30:57 PM1/29/13
to google-api-jav...@googlegroups.com
hi,
no i am still facing this issue

On Wed, Jan 30, 2013 at 12:02 AM, Dmitry Kirillov <dmitri....@gmail.com> wrote:
Hello Jaffar!
 
I'm experiencing the same behavior in IE10. Have you already found a solution?

пятница, 18 января 2013 г., 17:15:04 UTC+4 пользователь Jaffar Hussain написал:
My issue is slightly different everything is ok but popup is not closing and if user allows or disallow

--
You received this message because you are subscribed to the Google Groups "Google API JavaScript Client" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-api-javascrip...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
regards,
Jaffar Hussain
BSIT - NUST
Software Engineer - Rolustech
Skype:  jaffarfrombhakkar
Cell:      00923139024024

plspl

unread,
Mar 7, 2013, 4:07:20 PM3/7/13
to google-api-jav...@googlegroups.com
I have had similar problem. The popup does not automatically close. even after using the timeout. 

@Jaffar & @Dimitry - Did you guys manage to fix this?

sup...@stacktype.com

unread,
Mar 9, 2013, 3:07:13 AM3/9/13
to google-api-jav...@googlegroups.com
Have raised an issue for this - https://code.google.com/p/google-api-javascript-client/issues/detail?id=74. Please star this issue if you're still facing the problem.
Message has been deleted

Nuno Oliveira

unread,
Aug 13, 2013, 8:18:13 AM8/13/13
to google-api-jav...@googlegroups.com
Hi all,

I'm trying to retrieve all contacts from gmail. This works fine in Chrome but not in Firefox (23.0) and IE (8)
When I make the ajax call to retrieve the contacts, it never calls the callback (successGmail in my example)

// OAuth configurations   
    var config = {
      'client_id': 'xxxxxx.apps.googleusercontent.com',
    };

gapi.auth.authorize(config, function(data) {
      // login complete - now get token
      var token = gapi.auth.getToken();
      token.alt = 'json';
 // retrieve contacts
      jQuery.ajax({
        dataType: 'jsonp',
        data: token,
        success: function(data) { successGmail(data); }
      });
    });

Any thoughts about this? Thank you guys.

Regards,
Nuno Oliveira
Reply all
Reply to author
Forward
0 new messages