做了一些同步方面的调整
163博客总是同步不上,新浪博客被封过微博账号,然而依然阻止不了我增加微博同步的脚步,不过看评论多半会失败w
从微博开放平台申请好移动应用之后,在function.php增加下面的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 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; $get_post_title = get_post($post_ID)->post_title; if ($get_post_info->post_status == 'publish' && $_POST['original_post_status'] != 'publish') { $appkey='你的appkey'; $username='微博用户名'; $userpassword='微博密码'; $request = new WP_Http; $status = '【' . strip_tags($get_post_title) . '】 ' . mb_strimwidth(strip_tags(apply_filters('the_content', $get_post_centent)) , 0, 132, '...') . ' 全文地址:' . get_permalink($post_ID); $api_url = 'https://api.weibo.com/2/statuses/update.json'; $body = array('status' => $status,'source' => $appkey); $headers = array('Authorization' => 'Basic ' . base64_encode("$username:$userpassword")); $result = $request->post($api_url, array('body' => $body,'headers' => $headers)); } } add_action('publish_post', 'post_to_sina_weibo', 0);//给发布文章增加一个分享微博的动作 |
码字很辛苦,转载请注明来自空间中的空间的《做了一些同步方面的调整》
2016-02-24
和谐小本子·专
评论