【问题标题】:Getting Error 500 Using the C# APi for Migration使用 C# APi 进行迁移时出现错误 500
【发布时间】:2014-09-27 19:47:23
【问题描述】:

**我已经尝试了一些事情,甚至运行了另一个堆栈溢出帖子中的示例并不断收到相同的错误消息。我试过直接从消息中使用字节数组。获取并转换为 ASCCII,然后再转换为字节。我有一个使用 括号的消息 ID。

下面是我的大部分代码。

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;
    }

}

}

【问题讨论】:

    标签: google-admin-sdk google-groups-migration


    【解决方案1】:

    我设法解决了上面代码中的这一行是错误的

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

    而不是使用组电子邮件发送 groupid,api 对 google 页面中提供的示例的描述有误。

    错误 500 并不能很好地描述问题,但经过大量试验和错误后,这些是我的发现。

    【讨论】:

      猜你喜欢
      • 2014-11-30
      • 2018-12-20
      • 2020-01-03
      • 1970-01-01
      • 2014-11-03
      • 2018-11-01
      • 2022-01-12
      • 1970-01-01
      • 2017-11-07
      相关资源
      最近更新 更多