1

在过去的条目中,我想出了如何检索某个配置文件 id 的指标数据: 使用 GData .NET Analytics API 时引发的异常

现在我想在 Google Analytics 中检索与我的帐户列表中的注册域名匹配的某个配置文件 ID,这在以前很容易,但在 Google 上一次升级到 Management/Core Reporting API 3.0 之后,旧的 2.3 提要已关闭并且 AccountsFeed 相关代码未按预期工作。

4

1 回答 1

1

使用此处发布的建议:http ://code.google.com/p/gdata-issues/issues/detail?can=2&start=0&num=100&q=&colspec=API%20ID%20Type%20Status%20Priority%20Stars%20Summary&groupby= &sort=&id=2955,我想出了这段代码来完成我需要的工作:

Imports Google
Imports Google.Analytics
Imports Google.GData.Analytics
Imports System.Collections.Generic
Imports System.Collections

Public Function GetProfileId(ByVal DomainText As String) As String

Dim Ids As String = String.Empty
Dim service As GData.Analytics.AnalyticsService = New GData.Analytics.AnalyticsService("MyAnalyticsService")
service.setUserCredentials(username, pass)

//Dim factory As GData.Client.GDataGAuthRequestFactory = CType(service.RequestFactory, GData.Client.GDataGAuthRequestFactory)
//factory.AccountType = "GOOGLE" 
//factory.UseSSL = True
//service.RequestFactory = factory    

Dim aF As DataFeed = service.Query(New DataQuery("https://www.googleapis.com/analytics/v2.4/management/accounts"))
Dim webPropsUrl As String = "" 
For Each o As GData.Client.AtomEntry In aF.Entries
     //webproperties
      If o.Title.Text.Contains(DomainText) Then
           webPropsUrl = o.Links.Item(1).HRef.Content
           Exit For
      End If
Next

Dim wpF As DataFeed = service.Query(New DataQuery(webPropsUrl))
Dim profileFeedUrl As String = "" 
For Each entry As DataEntry In wpF.Entries
    //profiles
     profileFeedUrl = entry.Links.Item(2).HRef.Content
     Exit For
Next

Dim prF As DataFeed = service.Query(New DataQuery(profileFeedUrl))
Dim profileUrl As String = "" 
For Each profd As DataEntry In prF.Entries
     profileUrl = profd.Links.Item(0).HRef.Content
     Exit For
Next

Dim profileId As String = ""
profileId = profileUrl.Split("/")(profileUrl.Split("/").Length - 1)

Return profileId

End Function
于 2012-09-03T02:16:43.620 回答