gpt4 book ai didi

php - Google Groups Directory API - 将用户添加到组引发错误 - PHP

转载 作者:行者123 更新时间:2023-12-05 02:22:50 26 4
gpt4 key购买 nike

我一直在尝试向我的 Google Apps 群组添加成员。我正在尝试使用以下代码,但会引发错误。不知道哪里出了问题。

include_once 'api-client/autoload.php';

$clientId = 'xxxxxxxxxxxxxxxxx.apps.googleusercontent.com';

$serviceAccountName = 'xxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com';

$delegatedAdmin = 'superadmin@domain.com';

$keyFile = 'mw-gxxxxxxxx.p12';

$appName = 'Example App';

$scopes = array(
'https://www.googleapis.com/auth/admin.directory.group'
);

$creds = new Google_Auth_AssertionCredentials(
$serviceAccountName,
$scopes,
file_get_contents($keyFile)
);

$creds->sub = $delegatedAdmin;

$client = new Google_Client();
$client->setApplicationName($appName);
$client->setClientId($clientId);
$client->setAssertionCredentials($creds);

$dir = new Google_Service_Directory($client);


$member = new Google_Service_Directory_Member(array('name@domain.com',
'kind' => 'admin#directory#member',
'role' => 'MEMBER',
'type' => 'USER'));

$list = $dir->members->insert('01tuee7433xxxxx', $member);

错误:

Fatal error: Uncaught exception 'Google_Service_Exception' with message 
'Error calling POST https://www.googleapis.com/admin/directory/v1/groups/01tuee7433v8xwz/members: (400) Missing required field: memberKey'

最佳答案

您应该在 $member 对象中添加 'email',因为它是在指定组中添加新成员的 POST 请求的必填字段。

$member = new Google_Service_Directory_Member(array('email' => 'name@domain.com',
'kind' => 'admin#directory#member',
'role' => 'MEMBER',
'type' => 'USER'));

可以引用这个documentation .

希望对您有所帮助!

关于php - Google Groups Directory API - 将用户添加到组引发错误 - PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27057265/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com