在Google目录API中,如何使用javascript添加用户?

在Google目录API中,如何使用javascript添加用户?,javascript,http-post,google-admin-sdk,google-directory-api,Javascript,Http Post,Google Admin Sdk,Google Directory Api,我有谷歌目录API的工作。这部分代码列出了目录中的前10个用户: gapi.client.directory.users.list({ “客户”:“我的客户”, “maxResults”:10, “订购人”:“电子邮件” }).然后(功能(响应){ var users=response.result.users; appendPre('用户:'); appendPre(“测试”) if(users&&users.length>0){ 对于(i=0;i

我有谷歌目录API的工作。这部分代码列出了目录中的前10个用户:

gapi.client.directory.users.list({
“客户”:“我的客户”,
“maxResults”:10,
“订购人”:“电子邮件”
}).然后(功能(响应){
var users=response.result.users;
appendPre('用户:');
appendPre(“测试”)
if(users&&users.length>0){
对于(i=0;i});尝试此虚拟数据源于并替换为正确的详细信息:

请求主体样本:

var user = {
    primaryEmail: 'liz@example.com',
    name: {
      givenName: 'Elizabeth',
      familyName: 'Smith'
    },
    // Generate a random password string.
    password: Math.random().toString(36)
  };

尝试将用户对象包装到资源对象中,如:

var user = {
  resource: {
   "password": "Testpass123",
   "primaryEmail": "albert.smith@mydomain.com",
   "name": {
      "givenName": "albert",
      "familyName": "smith"
    }
  }
}

我再也找不到这方面的参考资料了,所以也许其他人可以发布,但它对我有效。

这与我的请求正文非常相似,我相信两者都可以。我的问题是我不知道如何处理这个“user”变量。我尝试了
gapi.client.directory.users.insert(user)但这不起作用。换句话说:如何将请求正文插入user.insert函数?