{"id":2797,"date":"2014-08-01T16:19:41","date_gmt":"2014-08-01T07:19:41","guid":{"rendered":"http:\/\/apr20.net\/?p=2797"},"modified":"2014-08-01T16:19:41","modified_gmt":"2014-08-01T07:19:41","slug":"twitter-api-v1-1%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%84%e3%82%a4%e3%83%bc%e3%83%88%e6%8a%95%e7%a8%bf","status":"publish","type":"post","link":"https:\/\/apr20.net\/?p=2797","title":{"rendered":"twitter API v1.1\u3092\u4f7f\u3063\u3066\u30c4\u30a4\u30fc\u30c8\u6295\u7a3f"},"content":{"rendered":"<p>twitter\u306eAPI\u3092\u5229\u7528\u3057\u3066\u30c4\u30a4\u30fc\u30c8\u3059\u308b\u5fc5\u8981\u304c\u3042\u3063\u305f\u306e\u3067\u3001\u30e1\u30e2\u3002<\/p>\n<h3>\u6e96\u5099<\/h3>\n<p>\u307e\u305a\u3001<a href=\"https:\/\/dev.twitter.com\" target=\"_blank\">twitter\u306edev\u30b5\u30a4\u30c8<\/a>\u3067app\u767b\u9332\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\n<br \/>\n\u6b21\u306b\u3001\u30c4\u30a4\u30fc\u30c8\u3059\u308b\u969b\u306b\u5fc5\u8981\u306aOAuth\u3068\u3044\u3046\u8a8d\u8a3c\u4f5c\u696d\u3092\u7c21\u5358\u306b\u3057\u3066\u304f\u308c\u308bOAuth\u30e9\u30a4\u30d6\u30e9\u30ea<a href=\"https:\/\/github.com\/abraham\/twitteroauth\" target=\"_blank\">twitteroauth<\/a>\u3092\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002\u30ea\u30f3\u30af\u5148\u306b\u98db\u3093\u3060\u3089\u53f3\u4e0b\u306e\u65b9\u306bDownload ZIP\u3068\u3044\u3046\u30dc\u30bf\u30f3\u304c\u3042\u308b\u306e\u3067\u305d\u3053\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u51fa\u6765\u307e\u3059\u3002<\/p>\n<h3>\u8a2d\u5b9a<\/h3>\n<p>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305fzip\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u306b\u3042\u308btwitteroauth\u30d5\u30a9\u30eb\u30c0\u3092\u30b5\u30fc\u30d0\u3078\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002<br \/>\n\u3042\u3068\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u8a18\u8ff0\u3057\u305fphp\u30d5\u30a1\u30a4\u30eb\u3092\u9069\u5f53\u306a\u968e\u5c64\u306b\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3057\u307e\u3059\u3002<\/p>\n<p>[php]<br \/>\n\/\/twitteroauth.php\u3092\u30a4\u30f3\u30af\u30eb\u30fc\u30c9\u3057\u307e\u3059\u3002\u30d5\u30a1\u30a4\u30eb\u3078\u306e\u30d1\u30b9\u306f\u3054\u81ea\u5206\u3067\u6c7a\u3081\u3066\u4e0b\u3055\u3044\u3002<br \/>\nrequire_once(&quot;.\/twitteroauth.php&quot;);<\/p>\n<p>\/\/TwitterAPI\u958b\u767a\u8005\u30da\u30fc\u30b8\u3067\u3054\u78ba\u8a8d\u4e0b\u3055\u3044\u3002<br \/>\n\/\/Consumer key\u306e\u5024\u3092\u683c\u7d0d<br \/>\n$sConsumerKey = &quot;********************&quot;;<br \/>\n\/\/Consumer secret\u306e\u5024\u3092\u683c\u7d0d<br \/>\n$sConsumerSecret = &quot;****************************************&quot;;<br \/>\n\/\/Access Token\u306e\u5024\u3092\u683c\u7d0d<br \/>\n$sAccessToken = &quot;****************************************&quot;;<br \/>\n\/\/Access Token Secret\u306e\u5024\u3092\u683c\u7d0d<br \/>\n$sAccessTokenSecret = &quot;****************************************&quot;;<\/p>\n<p>\/\/OAuth\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3059\u308b<br \/>\n$twObj = new TwitterOAuth($sConsumerKey,$sConsumerSecret,$sAccessToken,$sAccessTokenSecret);<\/p>\n<p>\/\/\u545f\u304d\u3092POST\u3059\u308bAPI<br \/>\n$sTweet = &quot;\u545f\u304d\u306e\u30c6\u30b9\u30c8\u6295\u7a3f\u3067\u3059\u3002 (&quot;.date(&#8216;Y-m-d H:i:s&#8217;).&quot;)&quot;;<br \/>\n$vRequest = $twObj-&gt;OAuthRequest(&quot;https:\/\/api.twitter.com\/1.1\/statuses\/update.json&quot;,&quot;POST&quot;,array(&quot;status&quot; =&gt; $sTweet));<\/p>\n<p>\/\/Json\u30c7\u30fc\u30bf\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u5909\u66f4<br \/>\n$oObj = json_decode($vRequest);<\/p>\n<p>\/\/\u30a8\u30e9\u30fc<br \/>\nif(isset($oObj-&gt;{&#8216;errors&#8217;}) &amp;&amp; $oObj-&gt;{&#8216;errors&#8217;} != &#8221;){<br \/>\n    ?&gt;<br \/>\n&lt;h3&gt;\u30a8\u30e9\u30fc&lt;\/h3&gt;<br \/>\n    &lt;pre&gt;<br \/>\n    &lt;?php var_dump($oObj); ?&gt;<br \/>\n    &lt;\/pre&gt;<br \/>\n&lt;?php<br \/>\n\/\/\u6295\u7a3f\u5185\u5bb9<br \/>\n}else{<br \/>\n?&gt;<br \/>\n&lt;h3&gt;\u6210\u529f&lt;\/h3&gt;<br \/>\n    &lt;pre&gt;<br \/>\n    &lt;?php var_dump($oObj); ?&gt;<br \/>\n    &lt;\/pre&gt;<br \/>\n    &lt;?php<br \/>\n}[\/php]<\/p>\n<h4>\u8a2d\u5b9a\u304c\u5fc5\u8981\u306a\u7b87\u6240<\/h4>\n<p>1.twitteroauth\u306e\u30d1\u30b9\u306e\u8a2d\u5b9a\u3002<br \/>\n[php]require_once(&quot;.\/twitteroauth.php&quot;);<br \/>\n[\/php]<\/p>\n<p>2.API\u30ad\u30fc\u7b49\u306e\u8a2d\u5b9a\u3002\u5404\u30ad\u30fc\u306fdev\u30b5\u30a4\u30c8\u5185\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30da\u30fc\u30b8\u306b\u3042\u308bAPI Keys\u30bf\u30d6\u3092\u30af\u30ea\u30c3\u30af\u3059\u308b\u3068\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002Consumer key\u3001Consumer secret\u306e\u7b87\u6240\u306f\u3001\u305d\u308c\u305e\u308c\u3001API key \u3001 API secret\u3092\u8a18\u8ff0\u3057\u307e\u3059\u3002<\/p>\n<p>[php]<br \/>\n\/\/Consumer key\u306e\u5024\u3092\u683c\u7d0d<br \/>\n$sConsumerKey = &quot;********************&quot;;<br \/>\n\/\/Consumer secret\u306e\u5024\u3092\u683c\u7d0d<br \/>\n$sConsumerSecret = &quot;****************************************&quot;;<br \/>\n\/\/Access Token\u306e\u5024\u3092\u683c\u7d0d<br \/>\n$sAccessToken = &quot;****************************************&quot;;<br \/>\n\/\/Access Token Secret\u306e\u5024\u3092\u683c\u7d0d<br \/>\n$sAccessTokenSecret = &quot;****************************************&quot;;<br \/>\n[\/php]<\/p>\n<p>\u4e0a\u8a18\u306e1,2\u306e\u8a2d\u5b9a\u306b\u554f\u984c\u304c\u306a\u3051\u308c\u3070\u3001\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3060\u3051\u3067\u3001\u30c4\u30a4\u30fc\u30c8\u304c\u6295\u7a3f\u3055\u308c\u307e\u3059\u3002<\/p>\n<p><i class=\"icon-book\"><\/i> <small>\u5f15\u7528 : http:\/\/www.tryphp.net\/2013\/10\/25\/twitterapiv11_webapp\/<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>twitter\u306eAPI\u3092\u5229\u7528\u3057\u3066\u30c4\u30a4\u30fc\u30c8\u3059\u308b\u5fc5\u8981\u304c\u3042\u3063\u305f\u306e\u3067\u3001\u30e1\u30e2\u3002 \u6e96\u5099 \u307e\u305a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,16,2],"tags":[],"class_list":["post-2797","post","type-post","status-publish","format-standard","hentry","category-php","category-twitter-api","category-web"],"_links":{"self":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts\/2797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2797"}],"version-history":[{"count":0,"href":"https:\/\/apr20.net\/index.php?rest_route=\/wp\/v2\/posts\/2797\/revisions"}],"wp:attachment":[{"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/apr20.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}