作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
哇,我到处搜索,但找不到这个问题的“好”答案。这让我相信这很容易,没有人问,而且我很愚蠢,或者没有人能弄清楚。
当用户加入我们的网站时,我们希望在新用户注入(inject)过程中也将他们添加到我们的 Google 群组页面。我这里有这段代码,用于列出用户(尝试这样做只是为了让我开始)
$start = microtime(true);
require_once __DIR__ . '/google-api-php-client-2.2.1/vendor/autoload.php';
session_start();
date_default_timezone_set('America/Los_Angeles');
$REDIRECT_URI = 'http://localhost:8080';
$KEY_LOCATION = __DIR__ . '/client_secret.json';
$TOKEN_FILE = "token.txt";
$SCOPES = array(
Google_Service_Directory::ADMIN_DIRECTORY_GROUP_MEMBER
);
$client = new Google_Client();
$client->setApplicationName("Testing stuff");
$client->setAuthConfig($KEY_LOCATION);
// Incremental authorization
$client->setIncludeGrantedScopes(true);
$client->setAccessType('offline');
$client->setRedirectUri($REDIRECT_URI);
$client->setScopes($SCOPES);
$client->setAccessToken($_SESSION['accessToken']);
这就是我所得到的,请怜悯我。
*** 已更新 ***
我现在已经走到这一步了,感觉我已经更接近了。
<?php
require_once('google-api-php-client-2.2.1_PHP54/vendor/autoload.php');
$impersonateUser = 'XXX';
define('SCOPES', implode(' ', array(
Google_Service_Directory::ADMIN_DIRECTORY_GROUP_MEMBER) ));
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . 'c_json' );
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setSubject($impersonateUser);
$client->setScopes(SCOPES);
$dir = new Google_Service_Directory_Member($client);
$gPrimaryEmail = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e2c212c0e2c212c602d2123" rel="noreferrer noopener nofollow">[email protected]</a>';
$newUser = array( "email" => "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4e2c212c2c37777e7c7f7e0e2c212c602d2123" rel="noreferrer noopener nofollow">[email protected]</a>", "role" => "MEMBER");
$results = $dir->members->insert($newUser);
print_r($results);
PHP Fatal error: Call to a member function insert() on a non-object in /var/www/newUserForGroup/addUser.php on line 19
*** 已解决 ***
我对谷歌的整个系统是一团乱七八糟、答案为零的感到非常厌恶,但我设法弄清楚了这一点。如果其他人也遇到此问题,就是这样。
<?php
require_once('google-api-php-client-2.2.1_PHP54/vendor/autoload.php');
$impersonateUser = 'USER_EMAIL_WITH_ADMIN_ACCESS';
define('SCOPES', implode(' ', array(
Google_Service_Directory::ADMIN_DIRECTORY_GROUP_MEMBER))); // scope needed for function
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . 'json_c' ); // your json file
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setSubject($impersonateUser);
$client->setScopes(SCOPES);
$key = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f2b373a3e3b3b2d3a2c2c1f2b373a3e3b3b2d3a2c2c713c3032" rel="noreferrer noopener nofollow">[email protected]</a>"; // Your google groups "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="307855515c445844594043705855515c44585e5f471e535f5d" rel="noreferrer noopener nofollow">[email protected]</a>"
$service = new Google_Service_Directory($client);
$user = new Google_Service_Directory_Member(array('email' => '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bad3d9d1dbd8d5defad9c8dbd4df94d9d5d7" rel="noreferrer noopener nofollow">[email protected]</a>',
'kind' => 'admin#directory#member',
'role' => 'MEMBER',
'type' => 'USER'));
$list = $service->members->insert($key, $user);
现在我还必须提到,我遇到问题的主要原因是我没有正确设置域范围委派。您可以了解如何做到这一点here
最佳答案
* 已解决 *
我对谷歌的整个系统是一团乱七八糟、答案为零的感到非常厌恶,但我设法弄清楚了这一点。如果其他人也遇到此问题,就是这样。
<?php
require_once('google-api-php-client-2.2.1_PHP54/vendor/autoload.php');
$impersonateUser = 'USER_EMAIL_WITH_ADMIN_ACCESS';
define('SCOPES', implode(' ', array(
Google_Service_Directory::ADMIN_DIRECTORY_GROUP_MEMBER))); // scope needed for function
putenv('GOOGLE_APPLICATION_CREDENTIALS=' . 'json_c' ); // your json file
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setSubject($impersonateUser);
$client->setScopes(SCOPES);
$key = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="285c404d494c4c5a4d5b5b685c404d494c4c5a4d5b5b064b4745" rel="noreferrer noopener nofollow">[email protected]</a>"; // Your google groups "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afe7cacec3dbc7dbc6dfdcefc7cacec3dbc7c1c0d881ccc0c2" rel="noreferrer noopener nofollow">[email protected]</a>"
$service = new Google_Service_Directory($client);
$user = new Google_Service_Directory_Member(array('email' => '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2cbc1c9c3c0cdc6e2c1d0c3ccc78cc1cdcf" rel="noreferrer noopener nofollow">[email protected]</a>',
'kind' => 'admin#directory#member',
'role' => 'MEMBER',
'type' => 'USER'));
$list = $service->members->insert($key, $user);
现在我还必须提到,我遇到问题的主要原因是我没有正确设置域范围委派。您可以了解如何做到这一点here
干杯。
关于php - 通过 API 将新成员添加到我们的 Google 管理目录组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49742889/
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 2年前关闭。 Improve this questi
我是一名优秀的程序员,十分优秀!