Google Calendar API-未经授权,客户端无法使用此方法检索访问令牌,或者未经授权,客户端无法执行任何请求的范围

时间:2020-08-27 14:18:39

标签: php google-api google-calendar-api google-api-php-client service-accounts

现在我在Laravel中使用google-calendar-api,我想创建一个提醒,然后让用户决定是否要在其Google日历(基于他的gmail帐户)中显示它。
现在此代码可以正常工作: enter image description here

在尝试添加与会者时出现错误,Google在搜索时发现您需要“模拟”要邀请的用户,因此我尝试了下一种方法:

enter image description here

并收到此错误:

enter image description here

你们认为我做错了什么? 在我的Google Api控制台中,我使用了服务帐户,尝试了几个按键,并启用了域范围委托: enter image description here

如我所说,什么都行不通,我可以创建和列出活动,但不能邀请任何人。

谢谢!

1 个答案:

答案 0 :(得分:0)

错误消息

客户端无权使用此方法请求令牌

意味着您在Google开发者控制台上创建的客户端凭据与您使用的登录方式不符

您似乎正在使用设计用于服务帐户的代码

    // Create and configure a new client object.        
    $client = new Google_Client();
    $client->useApplicationDefaultCredentials();
    $client->addScope([YOUR SCOPES HERE]);
    return $client;

要使用此功能,您需要在Google开发者控制台上创建服务帐户凭据。你还没有。