获得一个特定的简档使用的GData .NET分析API 2.4注册帐户(Getting an spe

2019-07-31 08:01发布

:在过去的进入我想出如何获取指标数据进行一定的配置文件ID 使用的GData .NET分析API时抛出异常

现在我想找回我的帐户在谷歌Analytics(分析)名单上匹配的注册的域名有一定的个人资料的ID,这是很容易过,但最后谷歌之后升级到管理/核心报表API 3.0,旧的2.3饲料已被关闭并如期AccountsFeed相关的代码无法正常工作。

Answer 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= &排序=&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


文章来源: Getting an specific ProfileId from registered Accounts using GData .NET Analytics API 2.4