【问题标题】:Impersonate User using spatie / laravel-google-calendar使用 spatie / laravel-google-calendar 模拟用户
【发布时间】:2020-05-01 08:12:56
【问题描述】:

所以我想向在谷歌日历上创建的活动的与会者发送邀请电子邮件。但是当我这样做时

use Spatie\GoogleCalendar\Event as GoogleCalendarEvent;

$calendarEvent = new GoogleCalendarEvent;

$calendarEvent->name = $event->title;
$calendarEvent->startDateTime = $event->start_date;
$calendarEvent->endDateTime = $event->end_date;
$calendarEvent->addAttendee(['email' => 'isley269@gmail.com']);

$calendarEvent->save();

我得到错误

{ "error": 
    { "errors": [{ 
         "domain": "calendar", 
         "reason": "forbiddenForServiceAccounts", 
         "message": "Service accounts cannot invite attendees without Domain-Wide Delegation of Authority." 
    } ], 
     "code": 403, 
     "message": "Service accounts cannot invite attendees without Domain-Wide Delegation of Authority." 
    } 
}

所以我已经为服务凭证授予了域范围的权限。但我仍然收到错误,因为我尝试使用服务帐户邀请用户。我如何使用 Spatie\GoogleCalendar 在 laravel 7 中模拟使用此服务帐户的用户?

我尝试浏览 google 的 api 和 Spatie 的文档。但我找不到任何

【问题讨论】:

    标签: laravel google-calendar-api


    【解决方案1】:

    此问题已在 Google 的 Public Issue Tracker 上报告

    目前,不允许服务帐户在没有冒充的情况下邀请与会者。

    为了实现模拟,需要添加一行

    $client->setSubject('SPECIFY HERE THE USER TO IMPERSONATE');

    使用服务帐号创建new Google_Client() 时。

    更多信息请参见here

    【讨论】:

    • 我有同样的问题,我需要在哪里添加setSubject?使用 spatie / laravel-google-calendar 不需要做 new Google_Client()
    • 我已经修改了使用 spatie / laravel-google-calendar 的 GoogleCalendarFactory 添加 $client->setSubject('user mail');在新的 Google_Client() 之后。返回的错误是 "{ "error": "unauthorized_client", "error_description": "客户端未授权使用此方法检索访问令牌,或者客户端未授权访问任何请求的范围。" }"
    猜你喜欢
    • 2021-03-09
    • 2021-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 2012-08-09
    • 2021-06-09
    相关资源
    最近更新 更多