VB.NET-如何使用Blogger API V3向Blogspot发布帖子?
我正试图通过我的vb.net应用程序,使用。 但我每次都失败了。 有时返回403禁止的错误,有时返回未授权的错误。 请帮忙VB.NET-如何使用Blogger API V3向Blogspot发布帖子?,vb.net,api,google-api,blogger,blogspot,Vb.net,Api,Google Api,Blogger,Blogspot,我正试图通过我的vb.net应用程序,使用。 但我每次都失败了。 有时返回403禁止的错误,有时返回未授权的错误。 请帮忙 Dim mBlogID As String = "5861877551002158183" Dim AuthToken As String = "AIza......xxxx..........E6g" Dim post As String = "{""kind"": ""blogger#post"", ""blog"": { ""id"": """ &a
Dim mBlogID As String = "5861877551002158183"
Dim AuthToken As String = "AIza......xxxx..........E6g"
Dim post As String = "{""kind"": ""blogger#post"", ""blog"": { ""id"": """ & mBlogID & """}, ""title"": ""abc-title"", ""content"": ""abc-cont""}"
Dim request As HttpWebRequest = DirectCast(WebRequest.Create("https://www.googleapis.com/blogger/v3/blogs/" & mBlogID & "/posts?key=" & AuthToken), HttpWebRequest)
request.Method = "POST"
request.ContentLength = post.Length
request.ContentType = "application/json"
request.Headers.Add("Authorization: ", AuthToken) '<--- error here
Using requestStream As Stream = request.GetRequestStream()
Dim postBuffer As Byte() = Encoding.ASCII.GetBytes(post)
requestStream.Write(postBuffer, 0, postBuffer.Length)
End Using
Using response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse) '<--- Unauthorised error or 403 error here
Using responseStream As Stream = response.GetResponseStream()
Using responseReader As New StreamReader(responseStream)
'Dim json As String = responseReader.ReadToEnd()
'Dim PostURL As String = Regex.Match(json, """url"": ?""(?<id>.+)""").Groups("id").Value
MsgBox(json) 'want to read json response here.
'MsgBox(PostURL)
End Using
End Using
End Using
Dim mBlogID As String=“5861877551002158183”
Dim AuthToken As String=“AIza……xxxx…………E6g”
Dim post As String=“{”kind”“:“blogger#post”“blog”“:{”id”“:“&mBlogID&”“}”,“title”“:“abc title”“content”“:“abc cont”“}”
Dim请求为HttpWebRequest=DirectCast(WebRequest.Create(“https://www.googleapis.com/blogger/v3/blogs/“&mBlogID&”/posts?key=“&AuthToken),HttpWebRequest)
request.Method=“POST”
request.ContentLength=post.Length
request.ContentType=“应用程序/json”
添加(“授权:,AuthToken)”我建议查看。这篇文章有充分的解释。在你回答时,这个问题已经是10个月前的问题了。目前我正在做另一个项目,稍后会考虑你的解决方案。谢谢