<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>新浪微博相关文章列表 | 皇家元林</title>
	<atom:link href="https://hjyl.org/tags/%E6%96%B0%E6%B5%AA%E5%BE%AE%E5%8D%9A/feed/" rel="self" type="application/rss+xml" />
	<link>https://hjyl.org</link>
	<description>刘元林的个人博客</description>
	<lastBuildDate>Sat, 24 Feb 2018 10:21:52 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://img.hjyl.org/uploads/2019/10/cropped-about-me-32x32.png</url>
	<title>新浪微博相关文章列表 | 皇家元林</title>
	<link>https://hjyl.org</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>WordPress插件：wp-to-weibo</title>
		<link>https://hjyl.org/wp-to-weibo/</link>
					<comments>https://hjyl.org/wp-to-weibo/#comments</comments>
		
		<dc:creator><![CDATA[皇家元林]]></dc:creator>
		<pubDate>Thu, 08 Feb 2018 06:41:42 +0000</pubDate>
				<category><![CDATA[元林手札]]></category>
		<category><![CDATA[WordPress插件]]></category>
		<category><![CDATA[wp-to-weibo]]></category>
		<category><![CDATA[同步]]></category>
		<category><![CDATA[新浪微博]]></category>
		<guid isPermaLink="false">https://hjyl.org/?p=3499</guid>

					<description><![CDATA[首先介绍一下这个插件，wp-to-weibo就是WordPress同步到新浪微博的插件。之前很喜欢用朋友圈，可 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>首先介绍一下这个插件，wp-to-weibo就是WordPress同步到新浪微博的插件。之前很喜欢用朋友圈，可朋友真的多起来的时候，我又喜欢用微博了，或许哪天微博朋友多起来了，我又喜欢了Twitter。</p>
<p>前两年这个功能很多人用，现在用WordPress的人都没那么多了，好多这种插件代码的朋友都是N年前更新的。不过这代码又不是没用的。</p>
<p>这里要感谢<a href="https://hjyl.org/go/aHR0cHM6Ly96aGFuZ2dlLm5ldC81MDgyLmh0bWw=" rel="nofollow" target="_blank">张戈的博客</a>，他里面介绍了很多关于怎么同步到新浪微博的方法，怎么去发现问题，受益良多。而且他之前也做了这样的一个插件。所以我这个插件基本上也是从他的代码中提炼出来的。</p>
<p><figure id="attachment_3510" aria-describedby="caption-attachment-3510" style="width: 602px" class="wp-caption alignleft"><a href="https://img.hjyl.org/uploads/2018/02/QQ20180208214547.png"><img fetchpriority="high" decoding="async" src="https://img.hjyl.org/uploads/2018/02/QQ20180208214547.png" alt="wp-to-weibo" width="602" height="404" class="size-full wp-image-3510" title="QQ20180208214547.png" /></a><figcaption id="caption-attachment-3510" class="wp-caption-text">wp-to-weibo</figcaption></figure>从根本上说不是他的代码有问题，是微博的接口问题，之前他介绍的微博高级写入接口，我找了半天都没找到，最后只有头条文章高级写入接口比较符合，如果想申请头条文章发布的权限，好像还需要至少有发布过10篇以上这样的文章才行。不过从微博开发平台里申请微连接之后单独申请这样的接口就OK了。</p>
<p>但是我这边插件除了支持这个接口，还有一个接口还可以同步到微博，那就是分享接口——第三方分享接口，这个接口只要你申请微连接默认是有的。他同步的形式如上图所示，这几天我测试了N遍。</p>
<p>主要核心代码有两个：一是分享到微博的形式：</p>
<pre><code class="php">
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(!empty(get_post_format($post_ID))){
	if(get_post_format($post_ID) == 'aside') $get_post_format = __('aside','wp-to-weibo');
	if(get_post_format($post_ID) == 'gallery') $get_post_format =  __('gallery','wp-to-weibo');
	if(get_post_format($post_ID) == 'link') $get_post_format =  __('link','wp-to-weibo');
	if(get_post_format($post_ID) == 'image') $get_post_format =  __('image','wp-to-weibo');
	if(get_post_format($post_ID) == 'quote') $get_post_format =  __('quote','wp-to-weibo');
	if(get_post_format($post_ID) == 'status') $get_post_format =  __('status','wp-to-weibo');
	if(get_post_format($post_ID) == 'video') $get_post_format =  __('video','wp-to-weibo');
	if(get_post_format($post_ID) == 'audio') $get_post_format =  __('audio','wp-to-weibo');
	if(get_post_format($post_ID) == 'chat') $get_post_format = __('chat','wp-to-weibo');
   }else{
	$get_post_format = __('Headline', 'wp-to-weibo');
   }
   if ($get_post_info->post_status == 'publish') {
       $appkey = "新浪微博APPKEY";
       $username = “新浪微博账号”;
       $userpassword = “新浪微博密码”;
       $request = new WP_Http;
       $keywords = ""; 
 
       /* keywords of post */
       $tags = wp_get_post_tags($post_ID);
       foreach ($tags as $tag ) {
          $keywords = sprintf(__(' %1$s # %2$s # ', 'wp-to-weibo'), $keywords, $tag->name);
       }
 
      /* add keywords to post topic*/
     $string1 = sprintf(__('【 %1$s 】 %2$s : ','wp-to-weibo'), strip_tags($get_post_format), strip_tags( $get_post_title ));
     $string2 = sprintf(__('%1$s Read More %2$s', 'wp-to-weibo'), $keywords, get_permalink($post_ID));
 
     /* post num, sync failed if more */
     $wb_num = (138 - WeiboLength_test($string1.$string2))*2;
     $status = $string1.mb_strimwidth(strip_tags( apply_filters('the_content', $get_post_centent)),0, $wb_num,'...').$string2;
       /* get the thumbnail, or get the first pic */ 
		$url = get_mypost_thumbnail($post_ID);
		//$url = preg_replace('/https:\/\//i','http://',$url);
        $api_url = 'https://api.weibo.com/2/statuses/share.json'; /* API */
        $body = array('status' => $status,'source' => $appkey,'pic' => $url);
       $headers = array('Authorization' => 'Basic ' . base64_encode("$username:$userpassword"));
       $result = $request->post($api_url, array('body' => $body,'headers' => $headers));
       return json_encode($result);
    }
}</code></pre>
<p>另一种是以头条文章的形式：</p>
<pre><code class="php">function post_to_sina_toutiao($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;
   $get_the_excerpt = get_post($post_ID)->post_excerpt;
   if(!empty(get_post_format($post_ID))){
	if(get_post_format($post_ID) == 'aside') $get_post_format = __('aside','wp-to-weibo');
	if(get_post_format($post_ID) == 'gallery') $get_post_format =  __('gallery','wp-to-weibo');
	if(get_post_format($post_ID) == 'link') $get_post_format =  __('link','wp-to-weibo');
	if(get_post_format($post_ID) == 'image') $get_post_format =  __('image','wp-to-weibo');
	if(get_post_format($post_ID) == 'quote') $get_post_format =  __('quote','wp-to-weibo');
	if(get_post_format($post_ID) == 'status') $get_post_format =  __('status','wp-to-weibo');
	if(get_post_format($post_ID) == 'video') $get_post_format =  __('video','wp-to-weibo');
	if(get_post_format($post_ID) == 'audio') $get_post_format =  __('audio','wp-to-weibo');
	if(get_post_format($post_ID) == 'chat') $get_post_format = __('chat','wp-to-weibo');
   }else{
	$get_post_format = __('Headline', 'wp-to-weibo');
   }
   if ($get_post_info->post_status == 'publish') {
       $appkey = "新浪微博APPKEY";
       $username = “新浪微博账号”;
       $userpassword = “新浪微博密码”;
       $request = new WP_Http;
       $keywords = ""; 
 
       /* keywords of post */
       $tags = wp_get_post_tags($post_ID);
       foreach ($tags as $tag ) {
          $keywords = sprintf(__(' %1$s # %2$s # ', 'wp-to-weibo'), $keywords, $tag->name);
       }
 
      /* add keywords to post topic*/
     $string1 = sprintf(__('【 %1$s 】 %2$s : ','wp-to-weibo'), strip_tags($get_post_format), strip_tags( $get_post_title ));
     $string2 = sprintf(__('%1$s Read More %2$s', 'wp-to-weibo'), $keywords, get_permalink($post_ID));
 
     /* post num, sync failed if more */
     $status = $string1.$get_post_centent.$string2;
       /* get the thumbnail, or get the first pic */ 
		$url = get_mypost_thumbnail($post_ID);
		//$url = preg_replace('/https:\/\//i','http://',$url);
        $api_url = 'https://api.weibo.com/proxy/article/publish.json'; 
        $body = array('title' => $get_post_title, 'text' => $get_the_excerpt, 'summary' => $get_the_excerpt, 'content' => $status, 'source' => $appkey, 'cover' => $url);
       $headers = array('Authorization' => 'Basic ' . base64_encode("$username:$userpassword"));
       $result = $request->post($api_url, array('body' => $body,'headers' => $headers));
       return json_encode($result);
    }
}</code></pre>
<p>其实两段代码基本一样，不同的是接口。另外，我还添加了post-format类型。如果不满意我的中文翻译，可以用poedit软件重新翻译，当然也可以反馈给我，我会考虑您的意见。</p>
<blockquote><p><strong><a href="https://hjyl.org/go/aHR0cHM6Ly93b3JkcHJlc3Mub3JnL3BsdWdpbnMvd3AtdG8td2VpYm8v" rel="nofollow" target="_blank">官方下载地址</a></strong></p></blockquote>
<p><del datetime="2018-02-10T02:12:49+00:00">此插件刚已经提交到官方插件库了，不知道什么时候可以审核通过。目前给大家一个下载地址：<a href="https://hjyl.org/go/aHR0cHM6Ly9jb2RpbmcubmV0L3UveWxnb2QvcC93cC10by13ZWliby9naXQvYXJjaGl2ZS9tYXN0ZXI=" rel="nofollow" target="_blank">WordPress插件wp-to-weibo</a></del></p>
<p>注意：如果以文章头条的形式，excerpt，即摘要内容必须有，否则同步失败。因为我把微博和导语部分是同步摘要的部分。其实这个插件做的不完美，特别是头条文章的形式，文章打开之后，显示的是格式化的文章，没有段落。有高手路过，可以帮我一起完善它，感谢！</p>
<p>== 已知bug ==<br />
1、如上所述，头条文章形式，打开文章无格式，无段落；<br />
2、文章更新后，还是会同步到微博，这个虽然可以加字段解决，但是我又不想在数据库里加个字段，而官方这个wp_is_post_revision貌似也不管用！</p>
<p>== changelog ==<br />
2018.02.08  开始提交该插件；<br />
2018.02.10  官方审核通过！</p>
<div id="content-copyright"><span style="font-weight:bold;text-shadow:0 1px 0 #ddd;font-size: 13px;">版权声明: </span><span style="font-size: 13px;">本文采用 <a href="https://hjyl.org/go/aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzMuMC8=" rel="nofollow" target="_blank">BY-NC-SA</a> 协议进行授权，如无注明均为原创，转载请注明转自 <a href="https://hjyl.org">皇家元林</a><br>本文链接: <a rel="bookmark" title="WordPress插件：wp-to-weibo" href="https://hjyl.org/wp-to-weibo/">WordPress插件：wp-to-weibo</a></span></div>]]></content:encoded>
					
					<wfw:commentRss>https://hjyl.org/wp-to-weibo/feed/</wfw:commentRss>
			<slash:comments>27</slash:comments>
		
		
			</item>
		<item>
		<title>我也来装个逼</title>
		<link>https://hjyl.org/zhuang-bi/</link>
					<comments>https://hjyl.org/zhuang-bi/#comments</comments>
		
		<dc:creator><![CDATA[皇家元林]]></dc:creator>
		<pubDate>Thu, 18 Jan 2018 13:11:56 +0000</pubDate>
				<category><![CDATA[生活点滴]]></category>
		<category><![CDATA[加个V]]></category>
		<category><![CDATA[微信公众号]]></category>
		<category><![CDATA[新浪微博]]></category>
		<category><![CDATA[认证]]></category>
		<guid isPermaLink="false">https://hjyl.org/?p=3318</guid>

					<description><![CDATA[这几天无聊，翻翻微博，又想起给我的新浪微博加个V（认证一下），之前失败的认证还在，我就直接修改了，可第一次又失 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>这几天无聊，翻翻微博，又想起给我的新浪微博加个V（认证一下），之前失败的认证还在，我就直接修改了，可第一次又失败了，说我的昵称不符合个人的气质，于是直接用我的名字全拼作为昵称。幸运的是通过了。</p>
<p><a href="https://img.hjyl.org/uploads/2018/01/weibov.png"><img decoding="async" src="https://img.hjyl.org/uploads/2018/01/weibov.png"  width="283" height="203" class="alignleft size-full wp-image-3319" title="weibov.png" alt="weibov.png" /></a>在很久以前，那个时候腾讯微博还是比较流行的，当时这两个微博还可以互相竞争一下，现在不行了，自从新浪微博去掉新浪，用上weibo.com这个域名之后，扶摇直上，而腾讯微博貌似已经不存在了似的。我当时想破了脑袋想给新浪微博加个V，就是不通过。我以前的同事<a href="https://hjyl.org/go/aHR0cHM6Ly93ZWliby5jb20vam95MTAwNA==" rel="nofollow" target="_blank">@Joy-Mr-Feng</a>帮我在他们公司设个职位，写个证明盖个章，就这样还认证失败了。在此也感谢他，我的好朋友，帮了我不少忙。当时还有个目的就是为了给我的微信公众号认证。那个时候新浪微博的认证还可以关联到微信公众号的认证，然后就可以有自定义菜单的功能，获得更多的权限，为此我还十几块钱在某宝上买了500个僵尸粉呢！可现在不行了，现在的微信公众号只能花钱年审认证。所以我对这个也死心了。没意思。想不通的是腾讯搞得东西还得让外面的公司进行认证，还要花钱，更想不通的是那些公司有什么资格对我们认证，还TM收费！</p>
<p>最近，我喜欢上了微博（新浪）。因为这上面熟人少。微信朋友圈的人都是周围的朋友，还有一些是大学的同学。可能我现在混得差吧，我也不想别人知道我现在的情况。所以我宁愿跟陌生人交“朋友 ”，然后仅此而已。很庆幸，知道我博客的熟人不多，之前跟他们提过，我的QQ签名上也有，我用的邮箱后缀也是，但他们对此不感冒。人们总是这样，对感兴趣的了解颇多，不感兴趣那真的一无所知。我这个博客在我周边的存在感是相当低的，所以有时候有些事我还是可以正大光明的吐槽在我博客上。</p>
<p>现在新浪微博的个人认证好像没那么严格了，当然基本要求还是有的，比如头像清晰，绑定手机，关注数≥50，粉丝数≥50，加V的好友互粉数≥2这些没用意义的。如果是你某某公司老板，搞点材料都是很轻松的。但像我这样混迹在贫穷大众最基层的屁民，想混个身份不容易，还好我爱好网站，就给自己一个站长的身份，我的博客。上传的材料就是备案网站的查询信息截图上传就可以了。</p>
<p>国内对这种言论的审查是非常严格，甚至不可理喻的。很久没去“国外”看看了，好像推特的名人没有这种加V的吧，他们反而可以说出自己想说的，然而我们加了V的，却不能乱说话。所以在国内微博只是信息的传递和宣传广告的作用。</p>
<p>不过就像胸前戴上了小红花一样，既然加了V，说的话是可以代表某某人态度的！</p>
<p>谢谢，欢迎<a href="https://hjyl.org/go/aHR0cHM6Ly93ZWliby5jb20veWxnb2Q=" rel="nofollow" target="_blank">@LIU-YUAN-LIN</a>！</p>
<div id="content-copyright"><span style="font-weight:bold;text-shadow:0 1px 0 #ddd;font-size: 13px;">版权声明: </span><span style="font-size: 13px;">本文采用 <a href="https://hjyl.org/go/aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzMuMC8=" rel="nofollow" target="_blank">BY-NC-SA</a> 协议进行授权，如无注明均为原创，转载请注明转自 <a href="https://hjyl.org">皇家元林</a><br>本文链接: <a rel="bookmark" title="我也来装个逼" href="https://hjyl.org/zhuang-bi/">我也来装个逼</a></span></div>]]></content:encoded>
					
					<wfw:commentRss>https://hjyl.org/zhuang-bi/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
