long2506 / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
Apache License 2.0
0 stars 0 forks source link

webmaster tool api : trying to verify website ownership #167

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I have followed the same steps to verify the site. I can successfully fetch 
the website but when trying to verify website it through me error "Bad Request 
URI" error code 400
2. I have followed all the steps mentioned in the documentation 
(https://developers.google.com/webmaster-tools/docs/2.0/developers_guide_protoco
l#AD_Verifying) but no success
3) Introduction -- I am developing a website where in backend section want to 
integrate a webmaster tool api where admin can add website, verify and do all 
the operations of webmaster tool from the website itself. I am developing 
website in PHP so if you can give me sample code then it will help me. I am 
trying by different from since 3 days but no success. Can you please help me.

What is the expected output? What do you see instead? I want to verify the 
website

Please provide any additional information below.
Below is sample code
$verify_code = $this->get_verification_code($new_site_url);echo 
'<pre>';print_r($verify_code);
                if(empty($verify_code['file_name'])) { return "Google does not return feed. Please contact to administrator";}
                if(file_exists("../".$verify_code['file_name'])) {
                    //return "Google verification file name already exists. Please check on site root and delete it.";
                }
                //echo '<pre>';print_r($verify_code);die;
                file_put_contents("../".$verify_code['file_name'],$verify_code['content']);
                /*$xml = <<<XML
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" 
xmlns:wt="http://schemas.google.com/webmasters/tools/2007">
<atom:id>http://www.sher.co.uk/sitemap.xml</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="htmlpage" in-use="true"/>
</atom:entry>XML;echo "test";die;*/
                $xml = '<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:wt="http://schemas.google.com/webmasters/tools/2007">';
                $xml .= '<atom:id>'.$new_site_url.'sitemap.xml</atom:id>';
                $xml .= '<atom:category scheme=\'http://schemas.google.com/g/2005#kind\' term=\'http://schemas.google.com/webmasters/tools/2007#site-info\'/>';
                $xml .= '<wt:verification-method type="htmlpage" in-use="true"/>';
                $xml .= '</atom:entry>';
                $url = self::SERVICEURI."feeds/sites/".$this->urlencoding($new_site_url)."/";

$ch = curl_init();
          $url = self::HOST . $url;
            $aut = $this->_auth;
            $header = array("Authorization: GoogleLogin auth=".$aut,"GData-Version: 2","Content-type: application/atom+xml");
            if($put) array_push($header, "X-HTTP-Method-Override: PUT");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
            curl_setopt($ch, CURLOPT_URL, $url);

         //curl_setopt($ch, CURLOPT_POST, true);
         //curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
        curl_setopt($ch, CURLOPT_PUT, 1); 
        curl_setopt($ch, CURLOPT_INFILE, $fp);
        curl_setopt($ch, CURLOPT_INFILESIZE,filesize('test.xml'));

            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            $r = curl_exec($ch);
            $info = curl_getinfo($ch);
            curl_close($ch);

Can you please sugggest me what wrong in it.

Thanks

Original issue reported on code.google.com by webdev.r...@gmail.com on 2 Aug 2012 at 7:38

GoogleCodeExporter commented 9 years ago
Sorry, this library does not cover the gdata APIs.

Original comment by ianbar...@google.com on 22 Mar 2013 at 2:36