我目前正在将Google Calendar API用于网络应用程序。但是,每小时都会提示我一个链接来验证快速启动访问权限。有谁知道如何解决这一问题?
细节:
我尝试过使用 OAUTH 和服务帐户,但没有成功。任何帮助是极大的赞赏。
下面是使用服务帐户的凭据创建 Google_Client 和 Srvice 对象的代码
function __construct()
{
Service account based client creation.
$this->client = new Google_Client();
$this->client->setApplicationName("Redu");
$this->client->setAuthConfig(CREDENTIALS_PATH);
$this->client->setScopes([SCOPES]);
$this->client->setSubject('redu@gmail.com');
$this->client->setAccessType('offline');
$this->service = new Google_Service_Calendar($this->client);
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用 $service 对象创建日历或创建事件时,我收到一条错误消息,指出未设置域范围权限。但是,当我创建服务帐户时,我确实启用了域范围委派。
编辑:
下面是我使用服务帐户密钥创建 Google_Client 并使用客户端为 redu@gmail.com 创建新日历的代码。请注意,我与 reduservice@subtle-breaker-280602.iam.gserviceaccount.com 共享了 redu@gmail.com 的日历,并将权限设置为“管理更改和管理共享”。我收到的错误位于代码下方:
require (__DIR__.'/../../../vendor/autoload.php');
define('CREDENTIALS_PATH', __DIR__ . '/redu_service_account_credentials.json');
define('SCOPES', Google_Service_Calendar::CALENDAR);
function createNewCalendar($userName) {
//Service account based client creation.
$client …Run Code Online (Sandbox Code Playgroud) php google-calendar-api google-api google-oauth google-api-php-client