Google Simple API Access - 需要授权,但如何?

时间:2012-04-21 13:27:00

标签: google-api

我正在尝试编写一个独立的perl应用程序,列出存储在Google Tasks中的所有任务。我开始相信我可以使用谷歌所谓的“简单的API访问”#34;因为它只是我的任务,而且它是只读的。

所以我做了以下事情:

#!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;

作为回报,我得到:

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

不幸的是,我不知道它目前需要什么授权。我尝试用以下代码替换最后一行:

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

并使用API​​控制台中列出的Google列出的客户ID,电子邮件地址和客户端密码 - 但他们都提供了Invalid Credentials

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

似乎不起作用,他们似乎已将其禁用为oauth2,并且尚未更新apply-for-an-api-key页面。改为使用Oauth2:

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

如果您需要api密钥,可以在此处获取:

https://code.google.com/apis/console
相关问题