Exception thrown when using GData .NET Analytics API
Asked Answered
B

2

1

I am facing an issue while trying to fetch data from GoogleAnalytics API on piece of code that has been working well just a couple of days ago.

For this I am referencing the following DLL's:

Google.GData.Analytics.dll
Google.GData.Client.dll
Google.GData.Extensions.dll

And I am using the following code:

Dim visits As String = String.Empty
Dim username As String = "[email protected]"
Dim pass As String = "mypassword"

Const dataFeedUrl As String = "https://www.google.com/analytics/feeds/data"
Dim query As AccountQuery = New AccountQuery()
Dim service As AnalyticsService = New AnalyticsService("MyWebAnalyticsService")
service.setUserCredentials(username, pass)
Dim accountFeed As AccountFeed = service.Query(query) ''----------> Exception thrown in this line: GDataRequestException Execution of request failed: https://www.google.com/analytics/feeds/accounts/default

I thought it had to do with a blocking to the account I was using but it wasn't the case because I verified registering the site for another analytics account and is still not working.

This code has been working flawlessly as I've said but all of a sudden has stopped doing so yesterday.

Could you please help me figuring out what's wrong?. Maybe the way the user credentials are set has changed and I am missing something.

Thank you very much for your help.

'----Update---- I managed to make it work and now I can query the visits for a desired domain. The code goes as follows:

Dim visits As String = String.Empty
Dim username As String = "[email protected]" 
Dim pass As String = "mypassword"

'Follow the instructions on https://developers.google.com/analytics/resources/articles/gdata-migration-guide (Create a Project in the Google APIs Console) to generate your key 'Once you have it set it as part of the querystring to request our GA service

Dim gkey As String = "key=yourkeystring"

'Set the new URI to retrieve the feed data and append it the generated key

Dim dataFeedUrl As String = "https://www.google.com/analytics/feeds/data?" & gkey   

'Create and authenticate on our service instance

Dim service As AnalyticsService = New AnalyticsService("MyAnaliticsService")
service.setUserCredentials(username, pass)  

'Use the profile id for the account you want to get ths visits from, you can find it
'logging in your analytics account, select the desired domain on your list (blue link) click on the administrator button and on the profiles tab find the profile
'configuration subtab, right there you will find the profile id in this case the eight characters long id 12345678

Dim query1 As DataQuery = New DataQuery(dataFeedUrl)
With query1            
    .Ids = "ga:12345678" 
    .Metrics = "ga:visits"
    .Sort = "ga:visits"
    .GAStartDate = DateTime.Now.AddMonths(-1).AddDays(-2).ToString("yyyy-MM-dd")
    .GAEndDate = DateTime.Now.ToString("yyyy-MM-dd")
    .StartIndex = 1
End With

'Use the generated datafeed based on the former query to get the visits

Dim dataFeedVisits As DataFeed = service.Query(query1)

For Each entry As DataEntry In dataFeedVisits.Entries
    Dim st As String = entry.Title.Text
    Dim ss As String = entry.Metrics(0).Value
    visits = ss
Next
Burnt answered 24/8, 2012 at 16:24 Comment(2)
i want to get available profile details.. have u any idea to how to get those details??? i try to get them, but couldn't. anyhow using this i sorted out my exception. now i need to get more details ...Wary
Check out this other post of mine sorting out this issue: #12241777 Hope it helps.Burnt
C
1

I have the same problem and it looks like google recently shut down the feed. It is answered in another post. Issue com.google.gdata.util.ResourceNotFoundException: Not Found with Google Analytic

Clown answered 24/8, 2012 at 20:37 Comment(1)
Fantastic user1623663. I am researching on it. Thank you very much.Burnt
B
0

Please make sure you registered your project in the APIs Console and you are sending the API Key with your requests.

If that is not the issue, inspecting the inner exception will give you more details about the error. As an alternative, you can use Fiddler to capture the HTTP request and the response. The latter will include a more descriptive error message.

Backfill answered 24/8, 2012 at 16:39 Comment(1)
Hi Claudio. I am trying to send the modified request now this way: google.com/analytics/feeds/…. However I am getting the same error. Maybe the error shows since I am not sure about the unique id used to retrieve analytics data (ids=ga:myganumber), I remember this number was different than the UA-xxxxxxxx-x one and I got it on .NET code after connecting to the remote server on the entry.ProfileId.Value object but since I can't connect I can't get it anymore, so how do I get this number and is my rewritten request correct?. Thank you.Burnt

© 2022 - 2024 — McMap. All rights reserved.