谷歌群组迁移C#API不工作 [英] Google Groups Migration C# API Not Working

查看:202
本文介绍了谷歌群组迁移C#API不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用C#谷歌群组迁移API和运气不好。

I'm trying to use the C# Google Groups Migration API and not having much luck.

我有以下的code:

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

...但是这将导致一个凭据无效例外。

我也试过以下内容:

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

...但失败:后端错误。内部的例外是:

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

The remote server returned an error: (503) Server Unavailable.

理想我preFER在使用2腿身份验证方法,因为它不会复制需要手动干预和粘贴一个auth-关键,但现在越来越任何工作将是一个加号。

Ideally I'd prefer the to use the 2 Legged Authenticator approach as it doesn't require manual intervention in copying and pasting an auth-key, but right now getting anything to work would be a plus.

任何帮助感激AP preciated!

Any help gratefully appreciated!

推荐答案

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

I had same problem, and asked to google's support team.

在结果中,我们发现这个问题,因为重现消息ID例如,在头格式无效。

In result, we found that this problem reproduce because "Message-ID" header in example has invalid format.

本错字已经被固定在 2013年8月12日。

请尽量邮件ID从NNNN@mail.samplegroup.com变更为&lt; NNNN@mail.samplegroup.com>

Please try to change Message-ID from NNNN@mail.samplegroup.com to <NNNN@mail.samplegroup.com>.

这篇关于谷歌群组迁移C#API不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆