這是我想要做的:我試圖在服務器端生成一個訪問令牌,將用於驗證用戶,如在此示例中:權限錯誤谷歌分析API和VB.net
https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/
我已經寫在VB.net這段代碼幾次嘗試後:
Public GA_Token As String
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim filename As String = {{path to p12 file}}
Dim serviceAccountEmail As String = {{service account generated email from IAM & Admin from console.developers.google.com of the form [email protected] name.iam.gserviceaccount.com}}
Dim certificate = New X509Certificate2(filename, "password", X509KeyStorageFlags.Exportable Or X509KeyStorageFlags.MachineKeySet Or X509KeyStorageFlags.PersistKeySet)
Dim Scopes As IEnumerable(Of String) = {AnalyticsService.Scope.AnalyticsReadonly}
Dim credential As New ServiceAccountCredential(New ServiceAccountCredential.Initializer(serviceAccountEmail) With {.Scopes = Scopes}.FromCertificate(certificate))
GA_Token = credential.GetAccessTokenForRequestAsync(Request.Url.ToString, CancellationToken.None).Result
End Sub
GA_Token然後寫我創建的分析頁面。
的問題是,當我去查看報告,我從Chrome中的403錯誤。 「{」error「:{」errors「:[{」domain「:」global「,」reason「:」insufficientPermissions「,」message「:」用戶沒有任何Google Analytics帳戶。「)。 }],「code」:403,「message」:「用戶沒有任何Google Analytics帳戶。」}}「headers:Objectcache-control:」private,max-age = 0「content-encoding:」gzip「content -length:「146」content-type:「application/json; charset = UTF-8」日期:「2016年11月18日星期五18:25:08 GMT」過期時間:「2016年11月18日星期五18:25:08 GMT 「服務器:」GSE「各不相同:」Origin,X-Origin「www-authenticate:」Bearer realm =「https://accounts.google.com/」,error = insufficient_scope,scope =「https://www.googleapis .com/auth/analytics.edit「」proto:Object__defineGetter__:defineGetter()defineSetter:defineSetter()lookupGetter:lookupGetter()lookupSetter:lookupSetter()構造:對象()hasOwnProperty:hasOwnProperty()isPrototypeOf:isPrototypeOf()propertyIsEnumerable:propertyIsEnumerable()的toLocaleString:的toLocaleString()的toString:的toString()的valueOf:的valueOf()得到原:原()設定原:原()結果:Objecterror:目標代碼:403errors:數組[1] 0:Objectlength:1__proto__:數組[0]消息:「用戶沒有任何Google Analytics帳戶。」 原:Object__proto__:Objectstatus:403statusText:null__proto__:Object_.nH @ CB = gapi.loaded_0:606_.du.Vh @ CB = gapi.loaded_0:742(匿名功能)@視圖-selector2.js:109h.o0 @ CB = gapi.loaded_0:75xs @ CB = gapi.loaded_0:78Wq @ CB = gapi.loaded_0:78_.C.uea @ CB = gapi.loaded_0:77Ap @ CB = gapi.loaded_0:71 CB = gapi.loaded_0: 67未捕獲的對象{result:Object,body:「{」error「:{」errors「:[{」domain「:」global「,」reason「:」我...呃沒有任何Google Analytics帳戶。 「,headers:Object,status:403,statusText:null}(匿名函數)@ cb = gapi.loaded_0:67
現在,我可以使用OAuth2協議生成令牌並在用戶登錄時顯示它在他/她的帳戶中,但我試圖繞過這一點。我遇到的問題是,我沒有看到我應該爲帳戶設置權限。我進入了IAM和Admin,並在兩個不同的服務帳戶上啓用了域範圍委派以進行測試。我設置了每個可以想象的權限(對於所有者+ 18個其他權限)。還有哪些地方需要設置權限,還是我可以忽略某些內容?
Wow 16 upvotes,1 downvote ...這是我見過的最低! –
對不起,但我沒有看到任何upvotes或downvotes。這是給我的嗎? – SEFL