我一直在尝试将成员添加到我的Google应用群组中。我正在尝试使用以下代码,但它会引发错误。不知道出了什么问题。
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'
答案 0 :(得分:3)
您应该添加'电子邮件'在$ member对象中,因为它是POST请求在指定组中添加新成员的必填字段。
$member = new Google_Service_Directory_Member(array('email' => 'name@domain.com',
'kind' => 'admin#directory#member',
'role' => 'MEMBER',
'type' => 'USER'));
您可以参考此documentation。
希望有所帮助!