Google网上论坛迁移C#API无效

时间:2013-02-05 14:12:12

标签: c# api google-apps google-email-migration google-groups-migration

我正在尝试使用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方法,因为它不需要手动干预复制和粘贴授权密钥,但现在让任何东西工作都是一个优点。

感谢任何帮助!

2 个答案:

答案 0 :(得分:0)

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

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

你会等待24小时并尝试重新跑步吗?配额会在每日基础知识上重置。

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

答案 1 :(得分:0)

我遇到了同样的问题,并向谷歌的支持团队询问。

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

此拼写错误已修复为August 12, 2013.

请尝试将消息ID从NNNN@mail.samplegroup.com更改为&lt; NNNN@mail.samplegroup.com>。