【问题标题】:Get user role/permissions for authenticated user Gmail API - PHP SDK获取经过身份验证的用户 Gmail API 的用户角色/权限 - PHP SDK
【发布时间】:2019-08-18 15:06:00
【问题描述】:

我正在尝试使用此PHP 代码获得电子邮件的角色(是否为超级管理员):

$email = 'an email with the same domain';
$credentials_file = '../service-account.json';
putenv('GOOGLE_APPLICATION_CREDENTIALS='.$credentials_file);

// Initialize Google Client
$client = new Google_Client();

$client->useApplicationDefaultCredentials();
// scopes to change signature
$client->setScopes(['https://www.googleapis.com/auth/gmail.settings.basic',
'https://www.googleapis.com/auth/gmail.settings.sharing',
'https://www.googleapis.com/auth/gmail.readonly', 'https://www.googleapis.com/auth/userinfo.profile']);

// Initialize Gmail
$gmail = new Google_Service_Gmail($client);
// set signature
$signature = new Google_Service_Gmail_SendAs();
// update signature

我正在使用最新的PHP SDK。该电子邮件始终与超级管理员电子邮件具有相同的域,但他/她并不总是超级管理员。

我试过的是:

var_dump($gmail->users->getProfile($email));

,但我收到一个错误:

失败的前提条件, 消息:错误请求”

我从这里读到 - Google Docs,我需要列出的权限之一,并且我拥有 https://www.googleapis.com/auth/gmail.readonly,我已将其添加到超级管理员用户的 Google 管理控制台中。

如何获取同域用户邮箱的角色?

【问题讨论】:

    标签: php gmail-api google-workspace


    【解决方案1】:

    基于the PHP API client docs,需要在调用new Google_Service_Gmail($client)之前添加$client->setSubject($email),因为调用Gmail API之前需要模拟用户。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      • 2017-04-05
      • 2020-10-20
      • 2021-10-14
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      相关资源
      最近更新 更多