httpsrequest google drive refreshtoken

时间:2012-12-29 16:18:22

标签: .net vb.net httpwebrequest google-drive-api

我正在尝试使用存储的refreshtoken创建一个http请求以获取新的accessstoken,以便我可以访问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()

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

1 个答案:

答案 0 :(得分:0)

您没有将您的凭据写入StreamWriter,它应该是......

streamwriter.Write(para)

这是假设他们当然是正确的。