2015-04-23 47 views
0

我正在使用Google Admin SDK API在Google中使用獨立C#代碼和所有操作(包括創建用戶,更新用戶,創建組,添加成員,獲取成員,搜索用戶等)來配置Google中的用戶/組。現在我正試圖調用組設置API來更新組設置的一些設置,但我得到一個羣組設置API:錯誤401

登錄所需的異常(401)。

我已經加入服務帳戶範圍組的設置,並在谷歌管理控制檯的安全設置添加了相同的組設置&啓用組設置在Developer控制檯 範圍:GroupssettingsService.Scope.AppsGroupsSettings 管理控制檯安全設置:https://www.googleapis.com/auth/apps.groups.settings

我不知道這裏有什麼問題,其餘全部API都工作正常,我試圖從API瀏覽器中的相同,並且也工作正常。

//Connect Google Snippet 

public static DirectoryService fnConnectGoogle() 
{ 
      Console.WriteLine("Connect to Google API"); 
      Console.WriteLine("====================="); 

      String serviceAccountEmail = "[email protected]"; 
      var certificate = new X509Certificate2(@"D:\CECV\Google\GoogleAppsProvisioning.p12", "notasecret", X509KeyStorageFlags.Exportable); 

      ServiceAccountCredential credential = new ServiceAccountCredential(
      new ServiceAccountCredential.Initializer(serviceAccountEmail) 
      { 
       User = "[email protected]", 
       Scopes = new[] { DirectoryService.Scope.AdminDirectoryUser, DirectoryService.Scope.AdminDirectoryGroup, 
        GroupssettingsService.Scope.AppsGroupsSettings} 
      }.FromCertificate(certificate)); 


      var dirservice = new DirectoryService(new BaseClientService.Initializer() 
      {enter code here 
       HttpClientInitializer = credential, 
       ApplicationName = "GoogleAppsProvisioning" 
      }); 
      return dirservice; 
} 

//Update Group Settings 


public static void fnUpdateGroupSetting(DirectoryService dirService) 
{ 
      GroupssettingsService groupSetting = new GroupssettingsService(); 
      // Groups group = new Groups(); 
      Google.Apis.Groupssettings.v1.Data.Groups group = new Google.Apis.Groupssettings.v1.Data.Groups(); 

      group.AllowWebPosting = "true"; 
      var g = groupSetting.Groups.Update(group, "[email protected]").Execute(); 
      Console.WriteLine("Group Settings updated successfully"+g.AllowWebPosting); 
} 
+0

這可能對您有幫助:http://stackoverflow.com/questions/13776174/google-group-settings-api-enabled-for-service-accounts – KRR

+0

我已編輯您的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –

回答

0

有你登錄的[email protected]激活它?我遇到同樣的問題,直到我意識到服務帳戶試圖充當用戶,如果用戶未被激活,它可能無法工作。儘管GroupSettings以外的API似乎沒有問題。