【发布时间】:2014-12-18 12:14:27
【问题描述】:
我需要通过服务帐户获得授权才能使用日历 API。
只要我发出 -Dim ok As Boolean = Await GetToken- 指令,我就会收到一个错误,我无法继续。请问有人可以帮助我吗? TIA
++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++ 错误详情: Google.Apis.Auth.OAuth2.Responses.TokenResponseException non è stata gestita H结果=-2146233088 消息=错误:“unauthorized_client”,描述:“请求中的未授权客户端或范围。”,Uri:“” 源=Microsoft.Threading.Tasks 堆栈跟踪: 在 Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在 Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(任务任务) 在 Google.Apis.Auth.OAuth2.ServiceAccountCredential.d__b.MoveNext() 在 c:\code\google.com\google-api-dotnet-client\default\Tools\Google.Apis.Release\bin\Debug\test\默认\Src\GoogleApis.Auth.DotNet4\OAuth2\ServiceAccountCredential.cs:riga 282 --- Fine traccia dello stack da posizione prente dove è stata Generata l'eccezione --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() 在 UGO_Cont.GoogleCalendarMgt.VB$StateMachine_0_GetAccessToken.MoveNext() 在 D:\inetpub\wwwroot\UGO_Cont.Web\Services\GoogleCalendarMgt.svc.vb:riga 160 --- Fine traccia dello stack da posizione prente dove è stata Generata l'eccezione --- 在 System.Runtime.CompilerServices.AsyncMethodBuilderCore.b__5(对象状态) 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback 回调, 对象状态, Boolean preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) 在 System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 在 System.Threading.ThreadPoolWorkQueue.Dispatch() 内部异常: ++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++
这是我使用的代码:
Private Const SVCACCMAIL = "999999999999-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com"
Private Const ACTIVITY_ID = "x9x9x9x9x9x9x9x9x9x9x9x9x9x9x9x9x9x9x9"
<OperationContract()>
Public Function InsertEvent(authToken As String, id_Azienda As Integer, id_Azione As Integer, id_Op As Integer) As String
Dim scopes As New List(Of String)
scopes.Add("https://www.googleapis.com/auth/calendar")
Dim inzlzr As New ServiceAccountCredential.Initializer(SVCACCMAIL) With {.User = SVCACCMAIL, .Scopes = scopes}
Dim credential As New ServiceAccountCredential(inzlzr.FromCertificate(GetCert))
GetAccessToken(credential)
End Function
Public Function GetCert() As X509Certificate2
Dim fileCert As String = "D:\inetpub\wwwroot\UGO_Cont.Web\UGO-Adv-CRM-999999999999999a.p12"
Dim cert = New X509Certificate2(fileCert, "notasecret", X509KeyStorageFlags.Exportable)
Return cert
End Function
Async Sub GetAccessToken(cr As ServiceAccountCredential)
Dim GetToken = cr.RequestAccessTokenAsync(System.Threading.CancellationToken.None)
Dim ok As Boolean = Await GetToken
Dim service As New CalendarService(New BaseClientService.Initializer() With {.ApplicationName = "Test calendar sync app", .HttpClientInitializer = cr})
Dim list As IList(Of CalendarListEntry) = service.CalendarList.List().Execute().Items()
End Sub
【问题讨论】:
标签: vb.net authorization