0

我需要使用网站管理员工具中的“元标记”来验证网站的所有权。我在 Vb.net 中使用 Google Webmaster Tool 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 错误,而如果成功,响应应该是站点提要,每个条目都已更新,并且“已验证”元素设置为“真”。

4

1 回答 1

0

我一直在研究谷歌网站管理员 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();
于 2013-04-29T13:07:55.067 回答