This article mainly introduced the baidu real-time push API interface application examples, very practical, friends in need can be under reference

good quality of the site can be found in baidu station platform under/data submission/sitemap see the function of real-time delivery, this tool is currently open invitation, baidu's real-time push API interface can push our time for the new post, baidu included in the first time.
 
Baidu station platform http://zhanzhang.baidu.com/

open baidu station platform, it opens at real-time push to add new data interface to get token API push address:
 
  http://ping.baidu.com/sitemap? Site=www.yourdomain.com &resource_name=sitemap&access _token=xxxxxxx 
 

share a net friend PHP code: real-time push  

PHP live post new article

socketopen way to push a sitemap


code is as follows:


  The function sitemap_ping_baidu ($urls) {
                $baidu_ping_url='ping.baidu.com';
                $_get='/sitemap ? Site=www.yourdomain.com &resource_name=sitemap&access _token=XXXXXXX ';
                $port=80;
                If (($IO=fsockopen ($baidu_ping_url, $port, $errno, $errstr, 50))!==false)   {
                        $send="POST $a get HTTP/1.1". "rn";
                        $send.='Accept: */*'. "rn";
                        $send.='cache-control: no - Cache. "rn";
 
                    $send.='Host:'. $baidu_ping_url. "rn";
                    $send.='Pragma: no cache -'. "rn";
                   //$send.="Referer: http://". $url. $get. "rn";
                   //$send.='the user-agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)'. "rn";
                     
                    $XML='<The ? The XML version="1.0" encoding="utf-8" ? ><Urlset> ';
                    The foreach ($urls as $url) {
                            $XML.='<Url> ';
                            $XML.='<Loc> <! [CDATA ['. $url.]] ></loc> ';
                            $XML.='<Lastmod> 'date (' Y -m - d'). '</lastmod> ';
                            $XML.='<Changefreq> Monthly ';
                            $XML.='<Priority> 0.8 </priority> ';
                            $XML.='</url> ';
                    }
                    $XML.='</urlset> ';

                    $send.='Content - Length:' the strlen ($XML). "rn";
                    $send.="Connection: Closernrn";

                    $send.=$XML. "rn";

                    Fputs ($IO, $send);

                    $return=' ';
                    While (! Feof ($I/o))
                    {
                            $return.=fread ($IO, 4096);
                    }
                    Return $return;
            } else {
                    Return false;
            }
    }
$return=sitemap_ping_baidu (array (' http://www.yourdomain.com/a.php?id=1 '));

after push baidu will return an XML document


code is as follows:


  <The ? The XML version="1.0" encoding="utf-8" ? >
        <MethodResponse>
                <Params>
                        <Param>
                                <Value>
                                        <Int> 200 </int>
                                </value>
                        <Param>
                </params>          
        </methodResponse>

status code meaning below

The

The

200 no use error, need to further observe the content of the return is correct
400 will be selected parameters did not provide a
405 does not support the request of the way, we only support the POST way to submit data
411 HTTP header lacks the Content - Length field
413 push data is too large, more than 10 MB limit
422 HTTP header Content - Length statement do not match the Length of the Length and the actual data
500 adsense platform server internal error

you might be interested in the article:

  • baidu map API application with geographical location information (js)
  • Java calls baidu location API service access location example
  • javascript use baidu map API and HTML 5 features for browser location
  • js calls baidu map API and dot on the map to add annotation
  • baidu map API application of the user's location


This concludes the body part