Skip to content

Instantly share code, notes, and snippets.

@davetheninja
Created September 22, 2009 06:48
Show Gist options
  • Save davetheninja/190858 to your computer and use it in GitHub Desktop.
Save davetheninja/190858 to your computer and use it in GitHub Desktop.
public class GoogleAccountQuery : IGoogleAccountQuery
{
readonly string _email;
readonly string _password;
readonly string _applicationName;
public GoogleAccountQuery(string email, string password, string applicationName)
{
_email = email;
_password = password;
_applicationName = applicationName;
}
public IList<GoogleAnalyticsAccount> GetAccounts()
{
var credentials = new GDataCredentials(_email, _password);
var requestSettings = new RequestSettings(_applicationName, credentials);
var accountsFeed = new AnalyticsRequest(requestSettings).GetAccounts();
var accounts = new List<GoogleAnalyticsAccount>();
accountsFeed.Entries.Each(x => accounts.Add(new GoogleAnalyticsAccount(x)));
return accounts;
}
And the error (from my test)
should contain 2 accounts : FailedExecution of request failed:
https://www.google.com/analytics/feeds/accounts/default
System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at Google.GData.Client.GDataRequest.Execute()
Google.GData.Client.GDataRequestException: Execution of request failed: https://www.google.com/analytics/feeds/accounts/default
at Google.GData.Client.GDataRequest.Execute()
at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
at Google.GData.Client.GDataGAuthRequest.Execute()
at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, ref Int64 contentLength)
at Google.GData.Client.Service.Query(FeedQuery feedQuery)
at Google.GData.Client.Feed`1.get_AtomFeed()
at Google.GData.Client.Feed`1.<get_Entries>d__0.MoveNext()
at Core.EnumerableExtensions.Each<T>(IEnumerable`1 collection, Action`1 action) in EnumerableExtensions.cs: line 10
at Core.GoogleAccountQuery.GetAccounts() in GoogleAccountQuery.cs: line 30
at Core.Specs.When_retreiving_the_google_accounts_with_a_valid_email_and_password.<.ctor>b__1() in GoogleAccountQuerySpecs.cs: line 16
at Machine.Specifications.Utility.RandomExtensionMethods.InvokeIfNotNull(Because because) in C:\Work\3rd Party\mspec\Source\Machine.Specifications\Utility\RandomExtensionMethods.cs: line 21
at Machine.Specifications.Model.Context.EstablishContext() in C:\Work\3rd Party\mspec\Source\Machine.Specifications\Model\Context.cs: line 89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment