0

ASP.Net을 사용하여 Google 사이트 확인 시스템을 개발하려고합니다. 또한 Google 탐색기 (https://developers.google.com/site-verification/v1/webResource/insert)를 사용하여 JSON 및 HTTP 요청 형식과 같은 요청 방법을 테스트합니다.Google 사이트 인증 API

이것은 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": [ 
    "[email protected]" 
], 
"site": { 
    "type": "site", 
    "identifier": "http://www.example.net/" 
} 
} 

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; 
     } 

사람이 이유를 알고 있나요?

+0

코드를 첨부 해주십시오. .NET 클라이언트 라이브러리 (https://code.google.com/p/google-api-dotnet-client/)를 사용합니까? – peleyal

+0

Google .Net 클라이언트 라이브러리를 사용하려고했습니다. 하지만 호환성이 너무나 많습니다. 나는 DotNetOpenOauth를 사용하고있다. 하지만 https://developers.google.com/site-verification/v1/webResource/insert에서 위의 오류가 발생합니다. 어쨌든 나는 코딩을하기도한다. – Chinthaka

답변

0

나는 직접 답변을 찾았습니다.

다음은 id가 인 JSA에서 GoogleApi로 전송되어야합니다. verificationMethos은 토큰을받을 때 선택해야합니다.

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

    { 
     "owners": [ 
      "[email protected]" ],  
     "site": { 
      "identifier": "http://test.sample.com/", 
      "type": "SITE" } 
    }