1

我正在创建一个谷歌驱动设备应用程序。我正在尝试阅读本教程: https ://developers.google.com/accounts/docs/OAuth2ForDevices

我第一时间就有货了 简单的 POST 步骤

这返回 400 错误请求:

  Try

        Dim request As HttpWebRequest
        Dim response As HttpWebResponse = Nothing
        Dim reader As StreamReader
        Dim data As StringBuilder
        Dim byteData() As Byte
        Dim postStream As Stream = Nothing
        request = DirectCast(WebRequest.Create("https://accounts.google.com/o/oauth2/device/code"), HttpWebRequest)
        request.Method = "POST"
        request.ContentType = "application/x-www-form-urlencoded"
        data = New StringBuilder()
        data.Append("client_id=XXXXXXXXXXX.apps.googleusercontent.com&")
        data.Append("scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive")
        byteData = UTF8Encoding.UTF8.GetBytes(data.ToString())
        request.ContentLength = byteData.Length
        Try
            postStream = request.GetRequestStream()
            postStream.Write(byteData, 0, byteData.Length)
        Finally
            If Not postStream Is Nothing Then postStream.Close()
        End Try

        Try
            ' Get response  
            response = DirectCast(request.GetResponse(), HttpWebResponse)

            ' Get the response stream into a reader  
            reader = New StreamReader(response.GetResponseStream())

            ' Console application output  
            tb1.Text = reader.ReadToEnd()
        Finally
            If Not response Is Nothing Then response.Close()
        End Try

    Catch ex As Exception
        tb1.Text = ex.Message
    End Try

我缺少发布信息吗?是 httpwebrequest 不是正确的工具吗?谢谢

4

1 回答 1

0

您不必编写自己的授权,您可以使用 .NET 客户端库。我们这里有 c# 的示例,您应该能够轻松地将它们转换为 VB.NET。

于 2012-11-16T14:51:53.940 回答