2

我一直在尝试将成员添加到我的谷歌应用程序组。我正在尝试使用以下代码,但它会引发错误。不知道做错了什么。

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'
4

1 回答 1

4

您应该在 $member 对象中添加“电子邮件”,因为它是 POST 请求在指定组中添加新成员的必填字段。

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

你可以参考这个文档

希望有帮助!

于 2014-11-21T17:36:10.593 回答