0

I am trying to develop Google site verification system using ASP.Net. Also using the Google explorer (https://developers.google.com/site-verification/v1/webResource/insert) to test the request method such as JSON and HTTP request format.

This is what I am sending to the Google.

POST https://www.googleapis.com/siteVerification/v1/webResource?verificationMethod=site&key={YOUR_API_KEY}

Content-Type:  application/json
Authorization:  Bearer xxxxxxxxxxxxxxx
X-JavaScript-User-Agent:  Google APIs Explorer

{
 "id": "myid",
 "owners": [
  "development@gmail.com"
 ],
 "site": {
  "type": "site",
  "identifier": "http://www.example.net/"
 }
}

I am getting following response from the Google.

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "backendError",
    "message": "Backend Error"
   }
  ],
  "code": 503,
  "message": "Backend Error"
 }
}

>

IAuthorizationState authorization;        
    protected void Page_Load(object sender, EventArgs e)
    {
        if (googleClient != null)
        {                                
            if (IsPostBack)
            {                    
                authorization = googleClient.ProcessUserAuthorization();
                if (authorization != null)
                {
                    this.AccessToken = authorization.AccessToken;

                }
                else if (this.AccessToken == null)
                {
                    googleClient.RequestUserAuthorization(scope: new[] { GoogleClient.Scopes.WebMaster.SiteVerification });
                }
            }                               
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
          if (authorization != null)
          {
              IOWebMasterInsertGraph webMasterInsertGraph = googleClient.RequestForVerification(authorization);               

          }
    }

public IOWebMasterInsertGraph RequestForVerification(IAuthorizationState authState)
        {
            if ((authState != null) && (authState.AccessToken != null))
            {
                WebRequest request = WebRequest.Create("https://www.googleapis.com/siteVerification/v1/webResource?verificationMethod=site");


                string path = HostingEnvironment.MapPath(@"~/App_Data/GoogleInsert.json");

                MemoryStream ms = new MemoryStream();
                FileStream fileStreem = new FileStream(path, FileMode.Open, FileAccess.Read);
                byte[] bytes = new byte[fileStreem.Length];
                fileStreem.Read(bytes, 0, (int)fileStreem.Length);
                ms.Write(bytes, 0, (int)fileStreem.Length);

                request.ContentType = "application/json";
                request.Method = "POST";
                request.ContentLength = ms.Length;
                ms.Seek(0, SeekOrigin.Begin);
                using (Stream requestStream = request.GetRequestStream())
                {
                    ms.CopyTo(requestStream);
                } 

                WebResponse response = request.GetResponse();

                if (response != null)
                {
                    Stream responseStream = response.GetResponseStream();

                    if (responseStream != null)
                    {
                        //return GoogleGraph.Deserialize(responseStream);
                        return WebMasterInsertGraph.Deserialize(responseStream);
                    }
                }
            }
            return null;
        }

Does anyone know the reason for this?

Chinthaka
  • 966
  • 1
  • 13
  • 42
  • Can you please attach your code? Do you use the .NET client library (https://code.google.com/p/google-api-dotnet-client/)? – peleyal Jul 03 '13 at 18:30
  • I was trying to use Google .Net client library. But there ware so many version in-compatibility. I am using DotNetOpenOauth. But I am getting above error with https://developers.google.com/site-verification/v1/webResource/insert. Anyway I will attache my coding too. – Chinthaka Jul 03 '13 at 18:51

2 Answers2

1

Why don't you use the Google .NET client library for Site verification? You even have a sample code for that. Try it out...

peleyal
  • 3,472
  • 1
  • 14
  • 25
0

I have found the answer myself.

The following has to be sent to the GoogleApi without the id in JSON. The verificationMethos has to be one you selected when getting token.

    POST /siteVerification/v1/webResource?verificationMethod=file HTTP/1.1 Host: www.googleapis.com 
    Content-length: 138 
    Content-type: application/json 
    Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 

    {   
       "owners": [
            "sample@gmail.com"   ],     
       "site": {
            "identifier": "http://test.sample.com/",
            "type": "SITE"   } 
    }
Chinthaka
  • 966
  • 1
  • 13
  • 42