wordpress对接新浪博客api
新浪微博主要用xmlrpc的方式发邮件,什么是xmlrpc?玩wordpress的同学应该知道wordpress也有这个东西,跟目录下就有这个文件,具体的内容查百度百科
我的理解是跟curl类似,不过xmlrpc是用xml格式传输
主要问题在在于传参数,我查了百度google都没有发现关于新浪xmlrpc发文章的参数说明文档,如果知道的小伙伴可以留个给我,让我把接口改进一下,本来想发送tag的,没有找到参数,下面是我发送文章到新浪微博的函数
代码如下 | 复制代码 |
/** * wordpress发送文章到新浪博客函数 * @param array $xmlclient * @param array $get_data * @param array $website */ function auto_send_to_boke($xmlclient,$get_data,$website){ $username=$xmlclient['username'];//新浪博客用户名 $password=$xmlclient['password'];//新浪博客密码 $xmlclient=$xmlclient['xmlclient'];//新浪博客的xmlrpc链接,可写死成 http://upload.move.blog.sina.com.cn/blog_rebuild/blog/xmlrpc.php $get_post_title=$get_data['post_title'];//文章标题 $get_post_content=$get_data['post_content'];//文章内容 $get_post_id=$get_data['post_id'];//文章id if(!$username || !$password || $$xmlclient || !$get_post_title || !$get_post_content){ echo "参数错误"; return false; } if(get_post_meta($get_post_id,'_auto_send_to_'.$website)){ echo get_permalink($get_post_id)."已经同步".$website."<br/>\n"; return false; } $client = new IXR_Client($xmlclient); $post1=array('title'=>$get_post_title,'description'=>$get_post_content,'categories'=>$categories); $params = array(1,$username,$password,$post1,true); $client->query('metaWeblog.newPost', $params); $get_response=$client->getResponse(); add_post_meta($get_post_id,'_auto_send_to_'.$website,$get_response,true); } |
如果你要实时同步的文章的话,添加下面的代码
代码如下 | 复制代码 |
function send_to_boke($post_ID){ $get_post_info = get_post($post_ID); $get_post['post_content'] = $get_post_info->post_content; $get_post['post_title'] = $get_post_info->post_title; $get_post['post_id'] =$post_ID $xmlclient['username']='';//新浪博客用户名 $xmlclient['password']='';//新浪博客密码 $xmlclient['xmlclient']='http://upload.move.blog.sina.com.cn/blog_rebuild/blog/xmlrpc.php'; auto_send_to_boke($xmlclient,$get_post,'sina'); } add_action('publish_post', 'send_to_boke', 0); |
时间: 2024-08-03 19:01:54