Google网上论坛目录API - 将用户添加到群组会引发错误 - PHP [英] Google Groups Directory API - Add user to group raises error - PHP
本文介绍了Google网上论坛目录API - 将用户添加到群组会引发错误 - PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在尝试将成员添加到我的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 ='示例应用程序';
$ 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);
$ b $ member $ new Google_Service_Directory_Member(array('name@domain.com',
'kind'=>'admin#directory#member',
'role'=>'会员',
'type'=>'USER'));
$ list = $ dir-> members-> insert('01tuee7433xxxxx',$ member);
错误:
致命错误:未收到的异常'Google_Service_Exception'带消息
'调用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'=>'会员',
'type'=>'USER'));
您可以参阅 documentation 。
希望有帮助! p>
I have been trying to add members to my google apps group. I am trying with following code but it raises error. Don't know what is doing wrong.
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);
The error:
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'
解决方案
You should add 'email' in the $member object, as it is a required field for the POST request to add a new member in the specified group.
$member = new Google_Service_Directory_Member(array('email' => 'name@domain.com',
'kind' => 'admin#directory#member',
'role' => 'MEMBER',
'type' => 'USER'));
You can refer to this documentation.
Hope that helps!
这篇关于Google网上论坛目录API - 将用户添加到群组会引发错误 - PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文