0

I need to verify the ownership of website using "metatag" in Webmaster Tools. I am using Google Webmaster Tool API in Vb.net. Following are the code logic.

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

In above code, after uploading API string, I am getting 400 Bad Request error, while If successful, the response should be Sites feed with each entry updated and the "verified" element set to "true".

Ashutosh
  • 1
  • 2

1 Answers1

0

I have been working on Google webmaster api and working with the similar process but stucking with feature to Add site using webmaster tool API. I am following the process explained in given URL: https://developers.google.com/oauthplayground/

I followed all three step. Step 1 : Need to go through the AOuth Login request and get the Authorization code in response.

Step 2 : I am getting the access token in exchange of authorization code.

Step 3 : And this the step I am stuck with.
Here, when I am going to consume this access token for next request, it showing me the unauthorized access (401).

Here is my code to generate the request to add website using webmaster tool api

WebClient client = new 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();