0

我正在尝试创建一个 http 请求以使用存储的刷新令牌获取新的访问令牌,以便我可以访问 Google 云端硬盘。

   Dim uri As String = "https://accounts.google.com/o/oauth2/token"

   Dim para As String = "code='" + cred.RefreshToken + "'&client_id='" + ClientCredentials.CLIENT_ID + "'&client_secret='" + ClientCredentials.CLIENT_SECRET + "'&grant_type='refresh_token'"

   Dim httpWebRequest As System.Net.HttpWebRequest = Net.WebRequest.Create(uri)
   httpWebRequest.Method = "POST"
   httpWebRequest.ContentType = "application/x-www-form-urlencoded"

   Dim requestStream As System.IO.Stream = httpWebRequest.GetRequestStream()
   Dim streamwriter As System.IO.StreamWriter = New System.IO.StreamWriter(requestStream)
   streamwriter.Write(para)
   streamwriter.Close()

   Dim httpWebResponse As System.Net.HttpWebResponse = httpWebRequest.GetResponse()

但这会返回一个错误的请求。我错过了什么?

4

1 回答 1

0

您没有将凭据写入 StreamWriter,它应该读取...

streamwriter.Write(para)

当然,这是假设它们是正确的。

于 2012-12-29T16:59:48.107 回答