<?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>-Flyぁ梦- &#187; API</title>
	<atom:link href="http://blog.11034.org/tag/api/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.11034.org</link>
	<description></description>
	<lastBuildDate>Sun, 22 Jun 2025 08:59:05 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>wp_sns_share更新至新浪API2.0，实现图片同步</title>
		<link>http://blog.11034.org/2012-07/sina_api_oauth_2.html</link>
		<comments>http://blog.11034.org/2012-07/sina_api_oauth_2.html#comments</comments>
		<pubDate>Thu, 19 Jul 2012 12:33:58 +0000</pubDate>
		<dc:creator><![CDATA[-Flyぁ梦-]]></dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[wp-sns-share]]></category>
		<category><![CDATA[新浪]]></category>
		<category><![CDATA[腾讯]]></category>

		<guid isPermaLink="false">http://blog.stariy.org/?p=1209</guid>
		<description><![CDATA[想实现新浪微博同步文章同步好久好久了，苦于在新浪API1.0下无论如何怎么尝试都行不通 （这篇博文中有介绍，半 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>想实现新浪微博同步文章同步好久好久了，苦于在新浪API1.0下无论如何怎么尝试都行不通 <img src="http://blog.11034.org/wp-includes/images/smilies/icon_biggrin.gif" alt=":-D" class="wp-smiley" style="height: 1em; max-height: 1em;" /> （<a title="wp_sns_share更新2.4，添加同步博文摘要输出" href="/2012-01/wp-sns-share_2-4.html" target="_blank">这篇博文中有介绍</a>，半年前了），其实很早就想转到2.0版本的API，但是苦于2.0版本的应用必须填写一个固定的callback地址，而wordpress插件的性质决定callback的域名完全不一样，这看似无法实现，也就搁置了。最近收到新浪开发者邮件提示，9月份API1.0版本即将弃用，而且之前有网友提示有其他插件实现了图片同步这一功能，最近趁暑假有时间就来好好继续研究一番。<span id="more-1209"></span></p>
<p>下了那个wordpress插件，叫social-medias-connect，的确是一款很强大的插件，不过某些功能要收费，而且表示在wordpress 3.3下chrome下无法进行sns授权绑定（授权的url被urlencoding了，算是bug吧）。看其源代码，果然是用了新浪API2.0版本的，然后就好奇它是如何越过callback设置的，原来利用了中间网页作二次跳转，即申请了一个SAE应用（xxx.sinaapp.com）。恍然大悟之后，模仿一下也申请了一个SAE服务，然后所有的授权登陆都在SAE的服务器上进行，然后根据url参数将授权后的access_token发回到wordpress博客中进行保存就好了。</p>
<p>然后聊聊新浪微博API2.0版本，对于1.0来说真的是有很大改进，特别是容易程度，在OAuth和调API方面都是。在OAuth上，省去了一个步骤而且再也不用计算复杂的签名了，只有授权后的一个code参数和再发一次HTTP POST请求后拿到的access_token参数即可，太方便了。而在调用API上，也仅仅只要这个access_token和其他必须的参数即可，自己写代码是非常方便的事了，再也没有计算签名等复杂的工作，而且2.0版本的API加入了好多的新方法，虽然支持上传图片只需要url但却没有权限。然后就是简单的HTTP POST请求的代码了，很顺利地搞定了同步图片的功能，很开心 <img src="http://blog.11034.org/wp-includes/images/smilies/icon_mrgreen.gif" alt=":mrgreen:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 。</p>
<p>但是OAuth 2.0最大的不好处在于access_token是有有效期的，而且很短只有7-30天不等（根据应用的权限等级），这对于一次性的APP来说没有影响，但对于博客中插件来说却是比较致命的，等于说每过一个期限都要去重新登陆授权一下，挺麻烦的。</p>
<p>然后又去研究了下腾讯微博API，发现也更新了很多，而且也有了OAuth 2.0版本，但为了懒得改代码也绕开access_token有效期这个坏处，1.0照用而且有只需要传url就能上传图片的API，真棒，这个要赞一下 <img src="http://blog.11034.org/wp-includes/images/smilies/icon_idea.gif" alt=":idea:" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 。于是腾讯微博也搞定了同步图片的功能。</p>
<p>这次的wp_sns_share插件加强了除以上功能外，还有不少新功能和其他改进的地方，此外还想实现twitter的微博同步（也是之前一直没搞定的），新版本2.6的更新还要过一段时间，要测试一下access_token过期后的表现和功能，估计8月应该能更新出来 <img src="http://blog.11034.org/wp-includes/images/smilies/icon_smile.gif" alt=":)" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 。</p>
<h4  class="related_post_title">看看 API , OAuth , wp-sns-share , 新浪 , 腾讯</h4><ul class="related_post"><li>2011-07-11 -- <a target="_blank" href="http://blog.11034.org/2011-07/wp-sns-share_2-3.html" title="wp-sns-share更新2.3">wp-sns-share更新2.3</a></li><li>2012-08-29 -- <a target="_blank" href="http://blog.11034.org/2012-08/wp-sns-share_2-6.html" title="wp_sns_share更新至2.6，增加图片同步">wp_sns_share更新至2.6，增加图片同步</a></li><li>2012-01-19 -- <a target="_blank" href="http://blog.11034.org/2012-01/wp-sns-share_2-4.html" title="wp_sns_share更新2.4，添加同步博文摘要输出">wp_sns_share更新2.4，添加同步博文摘要输出</a></li><li>2012-08-16 -- <a target="_blank" href="http://blog.11034.org/2012-08/fuck_renren.html" title="吐槽人人开放平台">吐槽人人开放平台</a></li><li>2012-02-10 -- <a target="_blank" href="http://blog.11034.org/2012-02/wp-sns-share_2-5.html" title="wp_sns_share更新2.5">wp_sns_share更新2.5</a></li></ul><h4 class="related_post_title">看看 Wordpress </h4><ul class="related_post"><li>2014-03-12 -- <a target="_blank" href="http://blog.11034.org/2014-03/new_url_to_template.html" title="wordpress改源码实现自定义URL到自定义页面">wordpress改源码实现自定义URL到自定义页面</a></li><li>2013-12-05 -- <a target="_blank" href="http://blog.11034.org/2013-12/wp-sns-share_2-8.html" title="wp_sns_share更新至2.8，添加小功能">wp_sns_share更新至2.8，添加小功能</a></li><li>2013-02-14 -- <a target="_blank" href="http://blog.11034.org/2013-02/wp_zjuem_in_wordpress.html" title="wp-zjuem，zju cc98表情系统 in wordpress">wp-zjuem，zju cc98表情系统 in wordpress</a></li><li>2012-09-26 -- <a target="_blank" href="http://blog.11034.org/2012-09/wordpress_post_actions.html" title="wordpress发布文章时的Action事件">wordpress发布文章时的Action事件</a></li><li>2012-08-29 -- <a target="_blank" href="http://blog.11034.org/2012-08/wp-sns-share_2-6.html" title="wp_sns_share更新至2.6，增加图片同步">wp_sns_share更新至2.6，增加图片同步</a></li>]]></content:encoded>
			<wfw:commentRss>http://blog.11034.org/2012-07/sina_api_oauth_2.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
