phungthaihoa / google-gdata

Automatically exported from code.google.com/p/google-gdata
0 stars 0 forks source link

System.Net.WebException : The remote server returned an error: (403) Forbidden. #647

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Following is the code I am using to get analytics data:

//Code Start
AnalyticsService asv = new AnalyticsService("Data Export");
asv.setUserCredentials("MyUsername", "MyPassword");
String baseUrl = "https://www.google.com/analytics/feeds/data";
DataQuery query = new DataQuery(baseUrl);
query.Ids = "MyClientAnalytic ID";
query.Dimensions = "ga:pagePath,ga:date";
query.Metrics = 
"ga:pageviews,ga:uniquePageviews,ga:timeOnPage,ga:bounces,ga:entrances,ga:exits"
;
query.Filters = "ga:medium==referral";
query.Sort = "-ga:pageviews";
query.NumberToRetrieve = 10000;
query.GAStartDate = "2012-01-07";
query.GAEndDate = "2013-01-07";
Uri url = query.Uri;

System.Diagnostics.Debug.WriteLine("URL: " + url.ToString());

// Send our request to the Analytics API and wait for the results to come back.
DataFeed feed = asv.Query(query);
//Code End

The above code was always working until recently I started getting this 
exception :

"System.Net.WebException : The remote server returned an error: (403) Forbidden"

I am going through all the answers (in the link : 
http://code.google.com/p/google-gdata/issues/detail?can=2&start=0&num=100&q=&col
spec=ID%20Type%20Status%20Owner%20Summary&groupby=&sort=&id=613 )but I m not 
sure how I can incorportate the solution provided by noemi.mo...@red-gate.com 
(#7) which says(I have no idea what he/she meant?):

"All I had to do is register in the project in the Google APIs console and use 
the API Key on my request and is now working fine again"

Also the solution provided by braintec...@gmail.com (#9)(I have no idea what 
he/she meant either?):

"It's working by changing the _autoPostData value to 
"“?accountType=HOSTED_OR_GOOGLE&Email={0}&Passwd={1}&service=analytics&sour
ce=thecyberwizard.comâ"

I am getting the results on https://ga-dev-tools.appspot.com/explorer/ and 
https://code.google.com/oauthplayground/ with all the same input values that I 
am sending through the code. Please help me.

Original issue reported on code.google.com by aa...@webqa.net on 5 Feb 2013 at 10:38

GoogleCodeExporter commented 8 years ago
have the same:
"System.Net.WebException : The remote server returned an error: (403) Forbidden"

AppsService service = new AppsService("domain", Username, Password);
service.RetrieveUser(user.email);

Original comment by zma...@kimep.kz on 6 Feb 2013 at 9:04

GoogleCodeExporter commented 8 years ago
what you mean zma...@kimep.kz?

Original comment by aa...@webqa.net on 6 Feb 2013 at 3:19