由于一些众所周知的原因,号称国际通用的头像系统在我国使用起来却越到了不小的麻烦,使用这一系统的国内博客头像就成了鸡肋,如果想要正常的使用也不是不可能的.
第一种方案就是自己的主机来预先存储这些头像,但是前提是你的主机可以连得上gravatar头像的服务器.
这种方案可以通过以下代码实现:
第一种方案就是自己的主机来预先存储这些头像,但是前提是你的主机可以连得上gravatar头像的服务器.
这种方案可以通过以下代码实现:
-->
不满足现状 不抱怨生活 DO MYSELF!
// 微博同步 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; //去掉文章内的html编码的空格、换行、tab等符号(如果你文章的编码格式是这样子,可以将下面的"//"去掉即开启此功能) //$get_post_centent = str_replace("\t", " ", str_replace("\n", " ", str_replace(" ", " ", $get_post_centent))); $get_post_title = get_post($post_ID)->post_title; 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,'...') . ' 全文地址:' . get_permalink($post_ID) ; $api_url = 'https://api.weibo.com/2/statuses/update.json'; $body = array( 'status' => $status, 'source'=>'4135063399'); $headers = array( 'Authorization' => 'Basic ' . '1fFjYc3uQHZpcF32fS5jb146MxFeY19DYF53aWfzNA==' ); /* 如果你使用改方法,请注释掉上面$headers = array( 'Authorization' => 'Basic ' . '1fFjYc3uQHZpcF32fS5jb146MxFeY19DYF53aWfzNA==' ); 换成如下代码 //你的新浪微博登陆名 $username = '' ; //你的新浪微博登陆密码 $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);
大概一般都应该知道是什么意思吧if( wp_is_post_revision($post_ID) ) return;//如果是修订版本$get_post_info = get_post($post_ID);//获取该文章信息$get_post_centent = get_post($post_ID)->post_content;//文章内容(不知道为什么在使用获取全部post_ID数据后没办法得到content,所以单独在请求下)$get_post_title = get_post($post_ID)->post_title;//文章标题if ( $get_post_info->post_status == ‘publish’ && $_POST['original_post_status'] != ‘publish’ ) {//判断是不是已经发表的文章或页面$status = ‘【’ . strip_tags( $get_post_title ) . ‘】 ‘ . mb_strimwidth(strip_tags( apply_filters(‘the_content’, $get_post_centent)),0, 132,’…’) . ‘ 全文地址:’ . get_permalink($post_ID) ;// 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’;//老接口用不了了,必须用v2.0$body = array( ‘status’ => $status, ‘source’=>’4135063399′);// $status 要发布的微博文本内容,内容不超过140个汉字
// $source 数值为应用的AppKey$headers = array( ‘Authorization’ => ‘Basic ‘ . ‘bate64编码加密’ );//这里的’bate64编码加密’位置,你自己到http://www.mxcz.net/tools/base64.aspx自己把你的帐号密码进行一下加密,格式是你新浪微博的登陆帐号:登陆密码(如,username@gmail.com:password)//如果不喜欢这么使用$headers = array( ‘Authorization’ => ‘Basic ‘ . ‘bate64编码加密’ ),就替换使用下面这个方法也可以,一样
//你的新浪微博登陆名
$username = ” ;
//你的新浪微博登陆密码
$password = ” ;
$headers = array( ‘Authorization’ => ‘Basic ‘ . base64_encode(‘$username:$password’));
必选
|
类型及范围
|
说明
| |
source
|
false
|
string
| 采用OAuth授权方式不需要此参数,其他授权方式为必填参数,数值为应用的AppKey |
status
|
true
|
string
| 要发布的微博文本内容,必须做URLencode,内容不超过140个汉字。 |
visible
|
false
|
int
| 微博的可见性,0:所有人能看,1:仅自己可见,2:密友可见,3:指定分组可见,默认为0。 |
access_token
|
false
|
string
| 采用OAuth授权方式为必填参数,其他授权方式不需要此参数,OAuth授权后获得。 |
list_id
|
false
|
string
| 微博的保护投递指定分组ID,只有当visible参数为3时生效且必选。 |
lat
|
false
|
float
| 纬度,有效范围:-90.0到+90.0,+表示北纬,默认为0.0。 |
long
|
false
|
float
| 经度,有效范围:-180.0到+180.0,+表示东经,默认为0.0。 |
annotations
|
false
|
string
| 元数据,主要是为了方便第三方应用记录一些适合于自己使用的信息,每条微博可以包含一个或者多个元数据,必须以json字串的形式提交,字串长度不超过512个字符,具体内容可以自定。 |