Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Simple API Access - Authorization required, but how?

Tags:

google-api

I'm trying write a standalone perl app that list all my tasks stored in Google Tasks. I'm led to believe I can use what Google call "Simple API Access" because it's just my tasks and it's read only.

So I did the following:

#!perl
use LWP;
my $browser = LWP::UserAgent->new;
my $list = "Iyrhxu8sRTVOhE4hUBr4W1kwNTI6MDow";
my $key = "<api key removed>";
my $url = "https://www.googleapis.com/tasks/v1/lists/$list/tasks?pp=1&key=$key";
print $browser->get($url)->content;

In return, I get:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

Unfortunately I've no idea what authorization it wants at this point. I tried replacing the last line with:

my $auth = "...";
print $browser->get($url, "Authorization", $auth)->content;

and using the Google listed Client ID, Email address and Client Secret listed in the API Console - but they all gave Invalid Credentials.

Can anyone help?

like image 697
Richard Avatar asked Apr 21 '12 13:04

Richard


People also ask

How do I use API that requires authentication?

Common API Authentication Methods The simplest way to handle authentication is through the use of HTTP, where the username and password are sent alongside every API call. You can use an HTTP header and encode the username and password.

How do I authorize my Google API key?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key.

How do I pass authorization in API?

You can pass in the API Key to our APIs either by using the HTTP Basic authentication header or by sending an api_key parameter via the query string or request body. If you use our client library CARTO. js, you only need to follow the authorization section and we will handle API Keys automatically for you.


1 Answers

Doesn't seem to work, they seem to have disabled it in favor of oauth2, and just haven't updated the apply-for-an-api-key page. Use Oauth2 instead:

https://developers.google.com/oauthplayground/

If you need an api key, you can get it here:

https://code.google.com/apis/console
like image 159
Kevin Avatar answered Sep 18 '22 17:09

Kevin