.net 谷歌分析API v3 OAuth2Authenticator问题
我在尝试针对谷歌分析API进行身份验证时遇到了一个奇怪的问题 有人能帮忙吗 代码如下:.net 谷歌分析API v3 OAuth2Authenticator问题,.net,vb.net,google-analytics,google-api,google-analytics-api,.net,Vb.net,Google Analytics,Google Api,Google Analytics Api,我在尝试针对谷歌分析API进行身份验证时遇到了一个奇怪的问题 有人能帮忙吗 代码如下: Imports DotNetOpenAuth.OAuth Imports Google.Apis.Analytics.v3 Imports Google.Apis.Analytics.v3.Data Imports Google.Apis.Authentication.OAuth2 Imports Google.Apis.Authentication.OAuth2.DotNetOpenAuth Imports
Imports DotNetOpenAuth.OAuth
Imports Google.Apis.Analytics.v3
Imports Google.Apis.Analytics.v3.Data
Imports Google.Apis.Authentication.OAuth2
Imports Google.Apis.Authentication.OAuth2.DotNetOpenAuth
Imports Google.Apis.Services
Imports Google.Apis.Util
Imports DotNetOpenAuth.OAuth2
Imports System.Security.Cryptography.X509Certificates
Public Class GoogleAnalytics
Private _scope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue()
Private _clientID As String = "nnnnnnnnnnnnnn@developer.gserviceaccount.com" '"1038052825878.apps.googleusercontent.com"
Private _keyFile As String = AppDomain.CurrentDomain.BaseDirectory & "\key\nnnnnnnnnnnnnn-privatekey.p12"
Private _keyPassword As String = "notasecret"
Private Function Auth() As OAuth2Authenticator(Of AssertionFlowClient)
Dim _desc As New AuthorizationServerDescription
_desc = GoogleAuthenticationServer.Description
Dim _key As X509Certificate2 = New X509Certificate2(_keyFile, _keyPassword, X509KeyStorageFlags.Exportable)
Dim _client As AssertionFlowClient = New AssertionFlowClient(_desc, _key) With {.ServiceAccountId = _clientID, .Scope = _scope}
Return New OAuth2Authenticator(Of AssertionFlowClient)(_client, AddressOf AssertionFlowClient.GetState)
End Function
Public Sub Analytics()
Dim _gas As AnalyticsService = New AnalyticsService(New BaseClientService.Initializer() With {.Authenticator = Auth()})
Dim _r As DataResource.GaResource.GetRequest = _gas.Data.Ga.Get("ga:nnnnnnnn",
"2013-01-01",
"2013-01-31",
"ga:visitors")
_r.Dimensions = "ga:pagePath"
_r.Sort = "-ga:visitors"
_r.MaxResults = 5
Dim _d As GaData = _r.Execute() '<------ ERROR HAPPENS HERE
For Each h In _d.ColumnHeaders
Console.WriteLine(h.Name)
Next
For Each row In _d.Rows
Console.WriteLine(row(0) & " ------ " + row(1))
Next
Console.ReadKey()
End Sub
End Class
就我的API控制台显示的内容而言,ga:ID是正确的,\u clientID
是正确的
我唯一能想到的另一件事是重新尝试生成.p12文件。。。除此之外,我不知所措我自己回答这个问题的唯一原因是这样它就不会被删除
我最后要做的就是将服务开发人员的电子邮件地址添加到我的分析帐户中,它就可以工作了 即使重新生成新的.p12文件也会产生此错误
Google.Apis.Requests.RequestError
User does not have any Google Analytics account. [403]
Errors [
Message[User does not have any Google Analytics account.] Location[ - ] Reason[insufficientPermissions] Domain[global]
]