I used the Sina Weibo open platform api to synchronize the website content to my own weibo. it is said that the wordpress website can synchronize articles to Sina Weibo when publishing a document and want to write a php code test in the same way. The following content references from: http://kinggoo.com/wpsycnweibo.htm
There are three methods for synchronizing data to Weibo: plug-ins, associated blogs, and non-plug-in Weibo interfaces.
First, you can search Baidu directly;
Second, because Sina has now canceled the option of associating blogs, but this feature has not been canceled, you can ask the following address, and then configure it.
The third method requires the Sina interface, as shown below:
1) create an on-site application on the Sina Weibo open platform. if the application fails to pass the review, the application from XX can be displayed below the microblog, such as the image from the KingGoo technology blog, you can search Baidu Google for the specific creation method. it is very simple (but if you have never passed the review and want to pass the review, I can provide paid help to Ga ~), After creating an application, the App Key of the application must be used below;
2) edit the functions. php file of your topic and add the following code at the end.
// Weibo synchronous function post_to_sina_weibo ($ post_ID) {if (wp_is_post_revision ($ post_ID) return; $ get_post_info = get_post ($ post_ID); $ get_post_centent = get_post ($ post_ID) -> post_content; // remove the html-encoded spaces, line breaks, tabs, and other symbols (if the encoding format of your article is like this, you can remove the following "//" to enable this function) // $ get_post_centent = str_replace ("\ t", "", str_replace ("\ n ","", str_replace ("", "", $ get_post_centent); $ get_post_title = get_post ($ post_ID)-> post_t Itle; if ($ get_post_info-> post_status = 'Publish '& $ _ POST ['original _ post_status']! = 'Publish ') {$ request = new WP_Http; $ status = '【'. strip_tags ($ get_post_title ). ']'. mb_strimwidth (strip_tags (apply_filters ('The _ content', $ get_post_centent), 0,132 ,'... '). 'Full text Address :'. get_permalink ($ post_ID); $ api_url =' https://api.weibo.com/2/statuses/update.json '; $ Body = array ('status' => $ status, 'source' => '2013'); $ headers = array ('authorization' => 'basic '. '1ffjyc3uqhzpcf32fs5jb146mxfey19dyf53awfzna = ');/* if you use the modification method, comment out the above $ headers = array ('authorization' => 'basic '. '1ffjyc3uqhzpcf32fs5jb146mxfey19dyf53awfzna = '); change to the following code // your Sina Weibo login name $ username = ''; // your Sina Weibo login password $ password = ''; $ headers = array ('authorization' => 'basic '. base64_encode ('$ username: $ password'); */$ result = $ request-> post ($ api_url, array ('body' => $ body, 'headers' => $ headers);} add_action ('Publish _ post', 'post _ to_sina_weibo ', 0 );
In this paper, we need to use the wordpress WP_Http class, find a substitute in github: https://github.com/duoshuo/easy-http
Description of this class: EasyHttp is a php class that helps you ignore different php environments and send http requests without any difference. You no longer need to check whether the current php environment supports curl, fsockopen, and fopen. EasyHttp automatically selects the most appropriate method to send http requests. EasyHttp is derived from the WP_Http class in WordPress. it removes all dependencies on other WordPress functions, splits them into different files, and simplifies them a little.
Based on the above content, write php code 1.php:
$ Status, 'source' => 'Here appkey'); $ headers = array ('authorization' => 'basic '. 'Here the 64-bit encoded username and password'); $ result = $ r-> post ($ api_url, array ('body' => $ body, 'headers' => $ headers); print_r ($ result);?>
When the browser accesses 1.php, the following content is returned:
Array ([headers] => Array ([server] => nginx/1.2.0 [date] => Sun, 13 Oct 2013 02:23:46 GMT [content-type] => text/plain; charset = UTF-8 [content-length] => 76 [connection] => close [api-server-ip] => 10.75.0.170 [vary] => Accept-Encoding [x-varnish] => 3299864740 [age] => 0 [via] => 1.1 varnish) [body] => Bad Content-Type header value: 'application/x-www-form-urlencoded; charset = '[response] => Array ([code] => 400 [message] => Bad Request) [cookies] => Array () [filename] =>)
It seems to be a 400 Bad Request, Baidu, which means "the server cannot understand the Request because of incorrect syntax format. The customer program cannot repeat the request without modification ."
How can I solve this problem?
Reply to discussion (solution)
Let's look at this blog, http://zhangge.net/4947.html.