PHP -Google API / GMAIL API-如何设置Quotauser



我需要在我的Google API和Gmail API呼叫上执行每用户配额。

https://developers.google.com/gmail/api/v1/reference/query-parameters

我如何设置 quotauser 使用php?

$client = new Google_Client();
$client->setApplicationName('My App');
$client->setAuthConfig('credentials.json');
$client->setAccessType('offline');
$client->setRedirectUri('my url');
$client->setScopes(
    array( Google_Service_Gmail::GMAIL_SEND,
           'email',
           'profile',
           'openid'
    )
);
$client->authenticate($_GET['code']);
$service = new Google_Service_Oauth2($client);
$info = $service->userinfo->get();
$gmail = new Google_Service_Gmail($client);
$gmail->users_messages->send('me', 'my message');

要执行每用户配额,您需要将唯一值(例如电子邮件(分配给" Quotauser"字段或将用户的IP分配给"用户IP"字段。[1]

这是实施每用户配额的工作代码示例(它在我的测试应用程序中使用gmail Quickstart [2]对我有用并添加下面的代码(:

$optParams = array('quotaUser' => "username@gsuite-domain.com");
$response = $gmail->users_messages->send("me", $message, $optParams);

在Google Cloud Platform Console(Console.Cloud.google.com(中,您可以编辑每个用户和每个API的配额限制。阅读有关如何编辑配额限制的说明[3]。

您可以检查每个Gmail API方法使用的"配额单元",这样您就可以计算出您想要多少配额日限制。[4]。

php usermessages_resource类文档来自gmail api [5]。

[1] https://developers.google.com/gmail/api/v1/reference/query-parameters

[2] https://developers.google.com/gmail/api/quickstart/php

[3] https://cloud.google.com/apis/docs/capping-api-usage

[4] https://developers.google.com/gmail/api/v1/reference/quota

[5] https://developers.google.com/resources/api-libraries/documentation/gmail/v1/php/php/latest/class-google_service_gmail_gmail_usersersersmessages_reserce_reserce.resource.html

最新更新