【问题标题】:VB.NET - How To Make a Post to Blogspot Using Blogger API V3?VB.NET - 如何使用 Blogger API V3 向 Blogspot 发帖?
【发布时间】:2013-06-18 08:25:38
【问题描述】:

我正在尝试使用 blogger api 通过我的 vb.net 应用程序发布新帖子。 但我每次都失败了。 有时它会返回 403 禁止错误,有时会返回未经授权的错误。 请帮忙。

 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

此代码返回此错误:指定值包含无效的 HTTP 标头字符。 参数名称:名称

有人可以解决吗?我只想在blogger 上发一个新帖子并阅读它的网址。

项目信息:-

平台:Visual Basic 2010

Blogger API 版本:V3

【问题讨论】:

    标签: vb.net api google-api blogger blogspot


    【解决方案1】:

    我建议查看this solution。该帖子有充分的解释。

    【讨论】:

    • 在您回答时,这个问题已经成为 10 个月大的问题。目前我正在开发另一个项目,稍后会查看您的解决方案。谢谢。
    猜你喜欢
    • 2014-06-25
    • 2013-10-15
    • 1970-01-01
    • 2020-02-23
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多