Always get "400 bad request"

562 views
Skip to first unread message

brett9897

unread,
Feb 9, 2012, 4:11:32 PM2/9/12
to Google API JavaScript Client
Can anyone tell me why this is a bad request?

function addToCalendar()
{
gapi.client.load('calendar', 'v3', function()
{
var request = gapi.client.calendar.events.quickAdd({
calendarId: 'primary',
text: 'Assignment due Feb 9th at 11:50 PM'
});

request.execute(function(resp)
{
console.log(resp);
});
});
}

I have already authenticated the user and all that appears to work
properly. I also get the same response just using the sample at:
https://code.google.com/p/google-api-javascript-client/source/browse/samples/authSample.html

I have set up my own server on localhost. Got a client ID for
localhost and changed it in the code. Got my own API key for
localhost and changed the code to reflect that also. All of the
authenticating works and I have the proper scopes to access the
calendar added in. Still both the calendar call and the plus call give
me a response of "400 Bad Request". There is no information on what
is actually wrong with the request so I was hoping someone knew.

brett9897

unread,
Feb 9, 2012, 4:24:25 PM2/9/12
to Google API JavaScript Client
Update: I even tried putting it on a real server and it still fails
the same way.

brett9897

unread,
Feb 9, 2012, 5:10:24 PM2/9/12
to Google API JavaScript Client
Nevermind. I figured out the issue. I didn't realize I needed to
enable my apikey for each google application I wanted to use.

Brendan

unread,
Feb 9, 2012, 5:13:55 PM2/9/12
to Google API JavaScript Client
I replaced your call in the auth sample at
https://code.google.com/p/google-api-javascript-client/source/browse/samples/authSample.html
and was able to get it working. I replaced only the value of apiKey,
clientId, and scopes in the HTML source.

You say the authSample gives you the same? If you load this URL it
does not retrieve your account info?
https://google-api-javascript-client.googlecode.com/hg/samples/authSample.html

I can't say for sure what's causing it without more context. But I
would double-check your API key's referers and Client ID's redirect
URIs and JavaScript origins, especially since you switched from
localhost to a server.

Brendan

unread,
Feb 9, 2012, 5:23:56 PM2/9/12
to Google API JavaScript Client
Missed your update. Glad it's working.

On Feb 9, 2:13 pm, Brendan <obr...@google.com> wrote:
> I replaced your call in the auth sample athttps://code.google.com/p/google-api-javascript-client/source/browse/...
> and was able to get it working. I replaced only the value of apiKey,
> clientId, and scopes in the HTML source.
>
> You say the authSample gives you the same? If you load this URL it
> does not retrieve your account info?https://google-api-javascript-client.googlecode.com/hg/samples/authSa...
Reply all
Reply to author
Forward
0 new messages