Reputation: 3
I'm trying to use the C# Google Groups Migration API and not having much luck.
I have the following 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: [email protected]
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();
}
...but this results in an Invalid Credentials
exception.
I also tried the following:
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: [email protected]
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);
}
}
...but that fails with: Backend Error
. The inner exception is:
The remote server returned an error: (503) Server Unavailable.
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.
Any help gratefully appreciated!
Upvotes: 0
Views: 627
Reputation: 1
I had same problem, and asked to google's support team.
In result, we found that this problem reproduce because "Message-ID" header in example has invalid format.
This typo has been fixed at August 12, 2013.
Please try to change Message-ID from [email protected] to <[email protected]>.
Upvotes: 0
Reputation: 1474
503 error usually indicated that you are hitting the API quota
https://developers.google.com/google-apps/groups-migration/v1/limits
Would you wait a 24 hours period and try to re-run again? The quota resets itself on a daily basics.
Additionally, you should tag your migration related question with google-email-migration and for group migration with google-groups-migration
Upvotes: 0