0

我正在尝试使用 C# Google Groups Migration API,但运气不佳。

我有以下代码:

public static void Main(string[] args)
{
    var body =
    @"Received: by 10.143.160.15 with HTTP; Mon, 16 Jul 2007 10:12:26 -0700 (PDT)
    Message-ID: NNNN@mail.samplegroup.com
    Date: Mon, 16 Jul 2007 10:12:26 -0700
    From: ""xxx""
    To: ""xxx""
    Subject: SUBJECT
    MIME-Version: 1.0
    Content-Type: text/plain; charset=ISO-8859-1; format=flowed
    Content-Transfer-Encoding: 7bit
    Content-Disposition: inline
    Delivered-To: xxx
    This is the body of the migrated email message.";

    var bytes = ASCIIEncoding.ASCII.GetBytes(body);

    var messageStream = new MemoryStream(bytes);

    var auth = new OAuth2LeggedAuthenticator("xxx.com", "xxx", "xxx", "xxx");
    var service = new GroupsmigrationService(auth);
    service.Key = "xxx";

    var request = service.Archive.Insert("xxx", messageStream, "message/rfc822");
    request.Upload();
}

...但这会导致Invalid Credentials异常。

我还尝试了以下方法:

public static class Program
{
    public static void Main(string[] args)
    {
        var body =
            @"Received: by 10.143.160.15 with HTTP; Mon, 16 Jul 2007 10:12:26 -0700 (PDT)
            Message-ID: NNNN@mail.samplegroup.com
            Date: Mon, 16 Jul 2007 10:12:26 -0700
            From: ""xxx""
            To: ""xxx""
            Subject: SUBJECT
            MIME-Version: 1.0
            Content-Type: text/plain; charset=ISO-8859-1; format=flowed
            Content-Transfer-Encoding: 7bit
            Content-Disposition: inline
            Delivered-To: xxx
            This is the body of the migrated email message.";

        var bytes = ASCIIEncoding.ASCII.GetBytes(body);

        var messageStream = new MemoryStream(bytes);

        // Register the authenticator.
        var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
        provider.ClientIdentifier = "xxx";
        provider.ClientSecret = "xxx";
        var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);

        // Create the service.
        var service = new GroupsmigrationService(auth);

        service.Key = "xxx";
        var request = service.Archive.Insert("xxx", messageStream, "message/rfc822");
        request.Upload();

        Console.ReadKey();
    }

    private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
    {
        // Get the auth URL:
        // IAuthorizationState state = new AuthorizationState(new[] { TasksService.Scopes.Tasks.GetStringValue() });
        IAuthorizationState state = new AuthorizationState(new[] { "https://www.googleapis.com/auth/apps.groups.migration" });

        state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
        Uri authUri = arg.RequestUserAuthorization(state);

        // Request authorization from the user (by opening a browser window):
        Process.Start(authUri.ToString());
        Console.Write("  Authorization Code: ");
        string authCode = Console.ReadLine();
        Console.WriteLine();

        // Retrieve the access token by using the authorization code:
        return arg.ProcessUserAuthorization(authCode, state);
    }
}

...但这失败了:Backend Error。内部异常是:

远程服务器返回错误:(503) 服务器不可用。

理想情况下,我更喜欢使用 2 Legged Authenticator 方法,因为它不需要手动干预复制和粘贴身份验证密钥,但现在让任何东西工作将是一个加号。

任何帮助感激不尽!

4

2 回答 2

0

我有同样的问题,并要求谷歌的支持团队。

结果,我们发现此问题重现,因为示例中的“Message-ID”标头格式无效。

此错字已于2013 年 8 月 12 日更正。

请尝试将 Message-ID 从 NNNN@mail.samplegroup.com 更改为 <NNNN@mail.samplegroup.com>。

于 2014-02-05T10:30:50.060 回答
0

503 错误通常表明您正在达到 API 配额

https://developers.google.com/google-apps/groups-migration/v1/limits

您会等待 24 小时后再尝试重新运行吗?配额会根据日常基础重新设置。

此外,您应该使用 google-email-migration 标记与迁移相关的问题,并使用 google-groups-migration 标记组迁移

于 2013-02-20T17:18:00.430 回答