Vb.net VB网上Google contacts API出现401错误

Vb.net VB网上Google contacts API出现401错误,vb.net,google-contacts-api,Vb.net,Google Contacts Api,我今天制作了一个vb net应用程序来获取我的联系人,它工作了一个小时,然后当我尝试使用我的应用程序时,我出现以下错误: 这是我正在使用的代码: Imports System.Threading Imports Google.Apis.Auth.OAuth2 Imports Google.Apis.Services Imports Google.Apis.Util.Store Imports Google.Contacts Imports Google.GData.Contacts Import

我今天制作了一个vb net应用程序来获取我的联系人,它工作了一个小时,然后当我尝试使用我的应用程序时,我出现以下错误:

这是我正在使用的代码:

Imports System.Threading
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Services
Imports Google.Apis.Util.Store
Imports Google.Contacts
Imports Google.GData.Contacts
Imports Google.GData.Client
Imports Google.GData.Extensions
Public Class Form1
Dim initializer = New BaseClientService.Initializer

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim Secrets = New ClientSecrets()
    Secrets.ClientId = "MYCLIENTID"
    Secrets.ClientSecret = "MYCLIENTSECRET"

    Dim scopes As String() = New String() {"https://www.googleapis.com/auth/contacts.readonly"}
    Try
        Dim credential = GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, scopes, "email@email.com", CancellationToken.None, New FileDataStore("MYAPPNAME")).Result()
        Dim parameters As New OAuth2Parameters()
        parameters.AccessToken = credential.Token.AccessToken
        parameters.RefreshToken = credential.Token.RefreshToken
        Dim settings As New RequestSettings("MYAPPNAME", parameters)
        Dim cr As New ContactsRequest(settings)
        Dim f As Feed(Of Contact) = cr.GetContacts()
        For Each c As Contact In f.Entries
            MsgBox(c.Name.FullName)
        Next
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub
End Class
我如何解决这个问题

为什么在表现出色之后会发生这种情况


谢谢

我通过改变这行的形式解决了这个问题:

Dim credential = GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, scopes,"email@email.com", CancellationToken.None, New FileDataStore("MYAPPNAME")).Result()
通过这句话:

Dim credential As UserCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(New ClientSecrets() With {
            .ClientId = "MYCLIENTID",
            .ClientSecret = "MYCLIENTSECRET"
        }, scopes, "email@gmail.com", CancellationToken.None, New FileDataStore("MYAPPNAME")).Result
把机密部分拿出来


谢谢大家的建议。

HTTP错误401表示您无权访问服务器内容,这意味着您的登录凭据有问题。谢谢。但在我这么说之前,您能告诉我为什么应用程序可以正常工作一小时吗?我怎么知道?可能发生的情况有无限多。也许你改变了一些你不应该改变的东西?也许谷歌改变了他们API中的一些东西??你在这一小时内没有做任何事情,比如向API发送很多请求?谷歌使用滑动窗口来限制他们的许多API。您可能已经超过了某种限制。根据您发布的图片,错误在第75行。我看不出我的手机是哪一条线路,你能在你的问题中分享吗?我不敢相信,同样,今天不起作用,我根本没有做任何更改,这个问题可能是Google Contacts API服务错误吗?我再问一个关于细节的问题