Baidu Real-time Push API interface application example, API example _php tutorial

Source: Internet
Author: User

Baidu Real-time Push API interface application example, API example


Site Quality good site can be in the Baidu Webmaster Platform/Data submitted/sitemap column to see the real-time push function, the current tool is invited to open, Baidu Real-time push API interface can be real-time push our new release of the article, to ensure that Baidu in the first time included.

Baidu Webmaster Platform http://zhanzhang.baidu.com/


Open the Baidu Webmaster platform, click to open the 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 PHP real-time push code written by a netizen:

PHP real-time push a new published article

Socketopen Mode Push Sitemap

Copy CodeThe code is as follows:
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,))!== false) {
$send = "POST $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. = ' user-agent:mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; trident/4.0) '. ' RN ";

$xml = ' <?xml version= ' 1.0 "encoding=" UTF-8 "?> ';
foreach ($urls as $url) {
$xml. = ' ;
$xml. = ' '.$url.' ;
$xml. = ' . Date (' y-m-d '). ' ';
$xml. = ' monthly ';
$xml. = ' 0.8 ';
$xml. = ' ;
}
$xml. = ' ';

$send. = ' content-length: '. strlen ($xml). " RN ";
$send. = "Connection:closernrn";

$send. = $xml. " RN ";

Fputs ($io, $send);

$return = ";
while (! feof ($io))
{
$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 the XML document

Copy the Code code as follows:
<?xml version= "1.0" encoding= "UTF-8"?>




200




The status code has the following meanings

200 No usage error, need to further observe whether the returned content is correct
400 Required parameter not provided
405 Unsupported request mode, we only support post method to submit data
411 Missing content-length field in HTTP header
413 Push data is too large to exceed the limit of 10MB
422 The length of the Content-length declaration in the HTTP header is inconsistent with the actual sent data length
500 Webmaster Platform Server Internal Error


How does the API interface work?

Your problem is too rough, the different API interfaces, the calls that are provided are not the same as the way you use them. In general, the provider of the API will provide the corresponding instructions and examples.

Baidu Sitemappost Push example how to use

With the developer account will enter the Baidu Open cloud platform, the following Web site is the development guide: developer.baidu.com/...qq.c2c. In principle, according to this guide can be successfully run Baidu provided by the sample program, but the personal feeling is not enough detailed, I wrote the following steps on their own experience.
When entering the website as above, click on the login in the upper right corner, after success, then display the management console in the upper right corner. Click on the admin console to enter light Application management, then click on the arrow to display 1.1 Mobile app management category, click Mobile App Management to enter application management.
Click to enter the following screen, fill in the application name, such as Push Test 2, click Save.

Click on the admin console to enter light Application management, then click on the arrow to display 1.1 Mobile app management category, click on Developer Services management into Figure 1.4, where the push test 2 is just new.

Figure 1.4 Developer Service Management
Click Push Test 2 to enter the red circle ID recorded in Figure 1.5, which will be written to the program later.

Figure 1.5 Basic information
Package= "Com.baidu.push.example"

Figure 1.6 Push settings
In the first use here may not know the application package name is what, then first introduced the Baidu Cloud push SDK. Download the Android version of the Client SDK package and app demo:developer.baidu.com/...entsdk from this URL. Below and unzip the package directory as follows \baidu-push-sdk-android-l2-3.2.0\demo, import the Demo into eclipse. If a compilation appears
Translation of the code will be converted to UTF-8, and generally will not report an error. This example program to run to the phone, you will find that the program can not receive the Baidu cloud in the push. is because also to modify mainfest.xml in the Api_key value is just push Test 2 in the basic Information API key shown in Figure 1.5 in the red circle. My changes are as follows:
Run again to receive the message Baidu Cloud push send. The following section describes the detailed testing process.
Mobile phone running Pushdemo software, enter the Baidu Cloud developer service Management, in the project name select just Push Test 2. Click on the left cloud push 1.7;
Click Notifications, Enter such as 1.8, in the title and message content to fill in the relevant content, and finally the most critical time to, it is best to run to the background or exit Pushdemo, so you can more image feel the push function, good click on the map of the send, about 1 seconds of time, you will hear the sound, you receive the push, 1.9 test results, this The message and the content in Figure 1.8 do not correspond, because the result is my next day. About messages and media testing I'm not going to tell you this, I tested it.

http://www.bkjia.com/PHPjc/897688.html www.bkjia.com true http://www.bkjia.com/PHPjc/897688.html techarticle Baidu Real-time Push API interface application example, API sample website Quality good site can be in the Baidu Webmaster Platform/Data submitted/sitemap column to see the real-time push function, the current tool ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.