0
试图授权对谷歌Analytics(分析)API,当我得到一个奇怪的问题。谷歌Analytics(分析)API V3 OAuth2Authenticator问题
有人能帮忙吗?
下面的代码:
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 = "[email protected]" '"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
我得到的错误是:
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]
]
的GA:ID是正确的,_clientID
是正确的那么远,因为我的API控制台正在显示我。
我能想到的唯一的另一件事是重新尝试生成.p12文件......除此之外,我很茫然
即使再生一个新的.p12文件正在产生这个错误 – Kevin