{"id":3649,"date":"2018-01-27T17:04:56","date_gmt":"2018-01-27T08:04:56","guid":{"rendered":"https:\/\/www.ws-meguro.com\/\/?p=3649"},"modified":"2018-03-02T18:13:55","modified_gmt":"2018-03-02T09:13:55","slug":"twitter-api%e3%81%a7%e3%83%84%e3%83%bc%e3%83%ab%e4%bd%9c%e3%82%8a%ef%bc%9a%e3%81%a8%e3%82%8a%e3%81%82%e3%81%88%e3%81%9a%e5%ae%8c%e6%88%90","status":"publish","type":"post","link":"https:\/\/www.wsmeguro.jp\/wp\/?p=3649","title":{"rendered":"Twitter API\u3067\u30c4\u30fc\u30eb\u4f5c\u308a\uff1a\u3068\u308a\u3042\u3048\u305a\u5b8c\u6210"},"content":{"rendered":"<p>\u30ad\u30fc\u30ef\u30fc\u30c9\u3092<a href=\"https:\/\/www.wsmeguro.jp\/\/tools\/twt\/\" rel=\"noopener\" target=\"_blank\">\u2019\u767b\u5c71\u2019\u306b\u8a2d\u5b9a\u3057\u3066Twitter\u3092\u691c\u7d22\u3057\u3066\u8868\u793a\u3059\u308b\u30c4\u30fc\u30eb<\/a>\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\u7c97\u3044\u3051\u3069\u3001\u3053\u3093\u306a\u3082\u3093\u3060\u3068\u3044\u3046\u611f\u3058\u3067\u3059\u3002<br \/>\n\u91cd\u8981\u306a\u60c5\u5831\u306a\u3089DB\u306b\u84c4\u7a4d\u3057\u3066\u3002\u3002\u3002\u3063\u3066\u306a\u308a\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u305d\u306e\u307e\u307e\u8868\u793a\u3057\u3066\u7d42\u308f\u308a\u3067\u3059\u3002<\/p>\n<pre class=\"lang:php decode:true \" >  require __DIR__ . '\/vendor\/autoload.php';\r\n\r\n  use mpyw\\Cowitter\\Client;\r\n\r\n  $ck = '';\r\n  $cs = '';\r\n  $at = '';\r\n  $ats = '';\r\n\r\n  $client = new Client([$ck, $cs, $at, $ats]);\r\n\r\n  \/\/ Search tweets\r\n\t$key_word = '\u767b\u5c71';\r\n\ttry {\r\n\t\t\/\/ Send a POST request to Twittern\r\n\t\t$tweets_params = ['q' =&gt; $key_word . ' exclude:retweets' , 'count' =&gt; '100' ];\r\n\t\t$tweets = $client-&gt;get('search\/tweets', $tweets_params );\r\n\t\techo 'Keyword = ' . $key_word . '&lt;br&gt;' . '&lt;hr&gt;';\r\n\t\t$cnt = 0;\r\n\t\tforeach ($tweets-&gt;statuses as $value) {\r\n\t\t\t$cnt = $cnt + 1;\r\n\t\t\t$text = htmlspecialchars($value-&gt;text, ENT_QUOTES, 'UTF-8', false);\r\n\t\t\tdisp_tweet($value, $text, $cnt);\r\n\t\t}\r\n\t} catch (\\RuntimeException $e) {\r\n\t\t\/\/ Jump here if an errors has occurred\r\n\t\techo \"Error: {$e-&gt;getMessage()}\\n\";\r\n\t}\r\n\r\n\tfunction disp_tweet($value, $text, $cnt){\r\n\t\t$screen_name = $value-&gt;user-&gt;screen_name;\r\n\t\t$updated = date('Y\/m\/d H:i', strtotime($value-&gt;created_at));\r\n\t\t$tweet_id = $value-&gt;id_str;\r\n\t\t$url = 'https:\/\/twitter.com\/' . $screen_name . '\/status\/' . $tweet_id;\r\n\r\n\t\techo '&lt;div class=\"tweetbox\"&gt;' . PHP_EOL;\r\n\t\techo '&lt;div class=\"counter\"&gt;No.' . $cnt . ' ' . $tweet_id . '&lt;\/div&gt;' . PHP_EOL;\r\n\t\techo '&lt;div class=\"meta\"&gt;&lt;a target=\"_blank\" href=\"' . $url . '\"&gt;' . $updated . '&lt;\/a&gt;' . '&lt;br&gt;@' . $screen_name .'&lt;\/div&gt;' . PHP_EOL;\r\n\t\techo '&lt;div class=\"tweet\"&gt;' . $text . '&lt;\/div&gt;' . PHP_EOL;\r\n\t\techo '&lt;\/div&gt;&lt;hr&gt;' . PHP_EOL;\r\n\t}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u2019\u767b\u5c71\u2019\u306b\u8a2d\u5b9a\u3057\u3066Twitter\u3092\u691c\u7d22\u3057\u3066\u8868\u793a\u3059\u308b\u30c4\u30fc\u30eb\u3092\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002\u7c97\u3044\u3051\u3069\u3001\u3053\u3093\u306a\u3082\u3093\u3060\u3068\u3044\u3046\u611f\u3058\u3067\u3059\u3002 \u91cd\u8981\u306a\u60c5\u5831\u306a\u3089DB\u306b\u84c4\u7a4d\u3057\u3066\u3002\u3002\u3002\u3063\u3066\u306a\u308a\u307e\u3059\u304c\u3001\u3053\u308c\u306f\u305d\u306e\u307e\u307e\u8868\u793a\u3057\u3066\u7d42\u308f\u308a\u3067\u3059\u3002 requ&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[454,514,485],"tags":[522,497,521],"class_list":["post-3649","post","type-post","status-publish","format-standard","hentry","category-php","category-twitter","category-485","tag-api","tag-php","tag-twitter"],"_links":{"self":[{"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3649","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3649"}],"version-history":[{"count":5,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3649\/revisions"}],"predecessor-version":[{"id":3682,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3649\/revisions\/3682"}],"wp:attachment":[{"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsmeguro.jp\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}