0
我正在嘗試爲.Net(VB.Net)運行Google Prediction API,但我遇到了一些問題。 有人有使用服務帳戶密鑰驗證的代碼示例?DotNet Google API身份驗證問題
我的代碼:
Dim myService As New PredictionService()
Dim myInput As New Data.Input()
Dim myInputData As New Data.Input.InputData()
Dim myListParameters As New List(Of Object)
myListParameters.Add("myInfo")
myInputData.CsvInstance = myListParameters
myInput.InputValue = myInputData
Dim myRequest As TrainedmodelsResource.PredictRequest = _
myService.Trainedmodels.Predict(myInput, "myProject", "myModel")
myRequest.OauthToken = "How can I get the OauthToken?"
myRequest.Key = "My API Key"
Dim myResponse = myRequest.Execute()
當我運行上面的代碼中,我得到的迴應:
Google.Apis.Requests.RequestError
Login Required [401]
Errors [
Message[Login Required] Location[Authorization - header] Reason[required] Domain[global]
]
那麼,在谷歌控制檯我創建了一個服務帳戶的關鍵,我做的JSON下載文件,並嘗試執行代碼下面生成authToken
Dim prediction As New PredictionService
Dim service = ServiceAccountCredential.FromServiceAccountData(_
New StreamReader("the path of jsonFile").BaseStream)
Dim auth As String = Await service.GetAccessTokenForRequestAsync()
當我運行此代碼時,得到th E錯誤: 「invalid_scope」,「空或丟失的範圍不允許的。」烏里:「」從我的變量服務
範圍屬性是空的,它是隻讀的。所以我不知道如何繼續。
Someboby能幫幫我嗎?
謝謝!