我正在尝试将某些内容集成到我们的网站中,以便在他们创建帐户时将新成员添加到我们的 Google 群组邮件列表中。我正在使用 Admin SDK 的 PHP API 来执行此操作,但没有运气
这是代码
include_once 'autoload.php';
$clientId = 'xxxxxxx.apps.googleusercontent.com';
$serviceAccountName = 'xxxxxx@developer.gserviceaccount.com';
$delegatedAdmin = 'admin@website.org';
$keyFile = 'key.p12';
$appName = 'App Name';
$scopes = array(
'https://www.googleapis.com/auth/admin.directory.group'
);
if (!($creds = new Google_Auth_AssertionCredentials(
$serviceAccountName,
$scopes,
file_get_contents($keyFile)
))) {
echo 'creds failed';
exit;
}
if (!($creds->sub = $delegatedAdmin)) {
echo 'sub failed';
exit;
}
if (!($client = new Google_Client())) {
echo 'obj creation failed failed';
exit;
}
if (!($client->setApplicationName($appName))) {
echo 'app name failed';
exit;
}
if (!($client->setClientId($clientId))) {
echo 'set id failed';
exit;
}
if (!($client->setAssertionCredentials($creds))) {
echo 'assertion failed';
exit;
}
if (!($dir = new Google_Service_Directory($client))) {
echo 'dir failed';
exit;
}
if (!($member = new Google_Service_Directory_Member(array(
'email' =>'validtestemail@test.test',
'kind' => 'admin#directory#member',
'role' => 'MEMBER',
'type' => 'USER')))) {
echo 'member failed';
exit;
}
if (!($list = $dir->members->insert('groupname@googlegroups.com', $member))) {
echo 'list failed';
exit;
}
echo 'good';
如果我运行它,代码会在设置的应用程序名称处停止,或者为此设置 $client 的任何属性。如果我将这些部分注释掉,我会得到一个空白页。