2014-09-27 33 views
1

**我已經嘗試了幾件事,即使運行了另一個堆棧溢出文章中的示例,並且仍然收到相同的錯誤消息。我試圖直接從消息中使用字節數組。然後轉到ASCCII然後回到字節。我有一個使用方括號的消息ID。獲取錯誤500使用C#APi進行遷移

下面是我的大部分代碼。

using Google.Apis.Admin.Directory.directory_v1; 
using Google.Apis.Auth.OAuth2; 
using Google.Apis.GroupsMigration.v1; 
using Google.Apis.Services; 
using Google.Apis.Util.Store; 
using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Text; 
using System.Threading; 
using System.Threading.Tasks; 

namespace GoogleEmailMigration 
{ 
class Program 
{ 
    [STAThread] 
    static void Main(string[] args) 
    { 
     /* 
     * The purpose of this tool is to migrate users into groups in the google business panel 
     */ 
     Console.WriteLine("Group Migration Tool Using Google Client"); 
     Console.WriteLine("===================="); 
     try 
     { 
      UserCredential credential; 
      var one =FillCredential(); 
      one.Wait(); 
      credential = one.Result; 

      MigrationDetails detail = new MigrationDetails() 
      { 
       EmailUserName = "***", 
       Domain = "****", 
       GroupName = "***", 
       Password = "***" 
      }; 

      detail.LoadGroupId(credential); 

      var service = new GroupsMigrationService(new BaseClientService.Initializer() 
      { 
       HttpClientInitializer = credential, 
       ApplicationName = "Switched On migration tool", 
      }); 

       /*Download all emails messages */ 
       GmailMessageProxy proxy = new GmailMessageProxy(){UserName = detail.EmailUserName+"@"+detail.Domain, Password=detail.Password}; 
       proxy.ActOnMessagesText((message) => 
       { 
        using (var mem = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(message))) 
        { 
         mem.Seek(0, SeekOrigin.Begin); 

         var uploadObject = service.Archive.Insert(detail.GroupId,mem,"message/rfc822"); 
         var result = uploadObject.Upload(); 
         Console.WriteLine("Status:"); 
         Console.WriteLine(result.Status); 
         Console.WriteLine("Bytes:"); 
         Console.WriteLine(result.BytesSent); 
         Console.WriteLine("Exception"); 
         Console.WriteLine(result.Exception.Message); 
        } 
       } 
        , (ex) => Console.WriteLine(ex));   

     } 
     catch (AggregateException ex) 
     { 
      foreach (var e in ex.InnerExceptions) 
      { 
       Console.WriteLine("ERROR: " + e.Message); 
      } 
     } 
     Console.WriteLine("Press any key to continue..."); 
     Console.ReadKey(); 
    } 

    private static async Task<UserCredential> FillCredential() 
    { 
     UserCredential credential; 
     using (var stream = new FileStream(@"***", FileMode.Open, FileAccess.Read)) 
     { 
      credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
       GoogleClientSecrets.Load(stream).Secrets, 
       new[] { @"https://www.googleapis.com/auth/apps.groups.migration", DirectoryService.Scope.AdminDirectoryGroupReadonly, DirectoryService.Scope.AdminDirectoryUserReadonly, DirectoryService.Scope.AdminDirectoryUserschemaReadonly }, 
       "user", CancellationToken.None, new FileDataStore("GroupsMigration")); 
     } 
     return credential; 
    } 

} 

}

回答

1

我設法解決它這條線在上面的代碼是錯誤的

var uploadObject = service.Archive.Insert(detail.GroupId,mem,"message/rfc822"); 

而不是發送GROUPID使用組電子郵件中的API有錯誤描述的示例在谷歌頁面提供。

錯誤500對問題描述不是很明顯,但經過大量的試驗和錯誤之後,這些都是我的發現。