如何在Google域中创建日历资源?

时间:2016-09-19 05:37:39

标签: google-apps-script google-admin-sdk admin-sdk

我有superadmin访问域名,我想使用Google Apps脚本创建日历资源。

通常我们可以在Google管理控制台中使用管理员权限创建日历资源(https://accounts.google.com)...But但我想自动化它。我查看了此页面(https://developers.google.com/admin-sdk/directory/v1/reference/resources/calendars/insert)..并将其修改为脚本,如下,但我收到了“错误请求”错误。

这里有什么问题?

这是我的代码 -

function myFunction() {
  var cus = 'email id';
  var res ={
    resource : 'Name of the resource',
    resourceDescription : "Meeting Room",
    resourceType : "Room"
  }
 AdminDirectory.Resources.Calendars.insert(res, cus); 
}`

3 个答案:

答案 0 :(得分:1)

resourceId resourceName 是必填字段。 resourceDescription和resourceType是可选的。你有资源'而不是resourceName,你没有提供一个Id。

请参阅此页上的紫色部分https://developers.google.com/admin-sdk/directory/v1/reference/resources/calendars/insert

答案 1 :(得分:1)

我已经向Kanchan的代码添加了更多行,以允许Google电子表格作为上传资源的源文件。

手册:

  1. 将“源文件的ID”替换为您要使用的电子表格的实际ID

  2. 脚本不会从工作表的第一行读取。您可以将它用于标题。我使用的列序列是:ResourceName,ResourceID,然后是ResourceType。示例文件位于:https://docs.google.com/spreadsheets/d/110UuIxsdJKWmff1RgMphcycbGOo_Ggrr1ON6PPj0tB4/

  3. 最好使用Google resourceName命名约定创建资源:https://support.google.com/a/answer/1033941

  4. ResourceId是您需要自己定义的字符串。我没有尝试使用相同的ID加载两个资源 - 我不知道如果你这样做会发生什么。

  5. 现在是代码块:

    function readwriteResources() {
    
      var cus = 'my_customer';
      var sourcefileid = "id of the sourcefile";
      var spreadsheet = SpreadsheetApp.openById(sourcefileid);
      var dataset = spreadsheet.getSheetByName('resources to load').getDataRange().getValues();
    
      for (i=1; i < dataset.length; i++) {
        var res = {
          resourceName : dataset[i][0],
          resourceId : dataset[i][1],
          resourceType : dataset[i][2]
        }
    
         AdminDirectory.Resources.Calendars.insert(res, cus);    
      }     
    }
    

答案 2 :(得分:0)

在通过Apps脚本创建新资源时,您没有获得ID,您自己提供。