我正在尝试使用 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 方法,因为它不需要手动干预复制和粘贴身份验证密钥,但现在让任何东西工作将是一个加号。
任何帮助感激不尽!