我需要使用网站管理员工具中的“metatag”验证网站的所有权 - 响应400:错误请求

时间:2013-04-18 06:47:21

标签: verification google-webmaster-tools google-data-api

我需要在网站站长工具中使用“metatag”来验证网站的所有权。我在Vb.net中使用Google网站管理员工具API。 以下是代码逻辑。

Dim client As New WebClient
    Try
        Dim query As String
        client.Headers.Add("Authorization: GoogleLogin auth=" + _auth)
        client.Headers.Add("GData-Version: 2")
        client.Headers.Add("Content-Type", "application/atom+xml")
        query = "<atom:entry xmlns:atom=""http://www.w3.org/2005/Atom"" " + _
            "xmlns:wt=""http://schemas.google.com/webmasters/tools/2007""> " + _
            "<atom:id>https://www.google.com/webmasters/tools/feeds/sites/http%3A%2F%2Ftestwebsite2.demos.classicinformatics.com%2F</atom:id> " + _
            "<atom:category scheme='http://schemas.google.com/g/2005#kind' " + _
            "term='http://schemas.google.com/webmasters/tools/2007#site-info'/> " + _
            "<wt:verification-method type=""metatag"" in-use=""true""/> " + _
        "</atom:entry>"

        Dim response = client.UploadString("https://www.google.com/webmasters/tools/feeds/sites/http%3A%2F%2Ftestwebsite2.demos.classicinformatics.com%2F", _
                                           "PUT", query)
Catch ex As WebException

End Try

在上面的代码中,上传API字符串后,我收到400 Bad Request错误,而如果成功,则响应应该是Sites feed,每个条目都更新,“Verified”元素设置为“true”。

1 个答案:

答案 0 :(得分:0)

我一直在使用Google网站管理员api并使用类似的流程,但仍然坚持使用网站管理员工具API添加网站功能。 我正在按照给定URL中解释的过程: https://developers.google.com/oauthplayground/

我遵循了所有三步。 步骤1:需要通过AOuth登录请求并获取授权代码作为回应。

第2步:我获取访问令牌以交换授权码。

第3步:这就是我坚持的步骤。
在这里,当我要为下一个请求使用此访问令牌时,它会向我显示未经授权的访问(401)。

以下是我使用网站管理员工具API

生成添加网站请求的代码

WebClient客户端=新WebClient();

            var query = "<atom:entry xmlns:atom='http://www.w3.org/2005/Atom'><atom:content src=\"" + address + "\" /></atom:entry>";
            client.Headers.Add("GData-Version", "2");
            client.Headers.Add("Content-Type", "application/atom+xml");
            client.Headers.Add("Authorization", "OAuth " + accessToken);

            var response = client.UploadString("https://www.google.com/webmasters/tools/feeds/sites/", "POST", query);
            //LoadList();
相关问题