{"id":226,"date":"2019-11-06T15:45:32","date_gmt":"2019-11-06T06:45:32","guid":{"rendered":"https:\/\/pocolog.bass-world.net\/tech\/?p=226"},"modified":"2019-11-06T15:45:32","modified_gmt":"2019-11-06T06:45:32","slug":"twitter-api-aggregate-tweet-modified","status":"publish","type":"post","link":"https:\/\/pocolog.bass-world.net\/tech\/2019\/twitter-api-aggregate-tweet-modified\/","title":{"rendered":"Twitter API \u3067\u7279\u5b9a\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u30c4\u30a4\u30fc\u30c8\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u3001\u4fee\u6b63\u7248"},"content":{"rendered":"\n<p>\u300c<a href=\"https:\/\/pocolog.bass-world.net\/tech\/2019\/twitter-api-aggregate-tweet\/\">Twitter API \u3067\u7279\u5b9a\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u30c4\u30a4\u30fc\u30c8\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5<\/a>\u300d\u3067\u3059\u304c\u3001\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3057\u3066\u60c5\u5831\u304c\u53d6\u308c\u306a\u3044\u3053\u3068\u304c\u3042\u308a\u3001\u305d\u306e\u8fba\u308a\u3092\u6539\u826f\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<blockquote><pre class=\"wp-block-code\"><code>&lt;?php\nrequire_once 'TwistOAuth.phar';\n\n$consumer_key = '<em>{your-consumer-key}<\/em>';\n$consumer_secret = '<em>{your-consumer-secret}<\/em>';\n$access_token = '<em>{your-access-token}<\/em>';\n$access_token_secret = '<em>{your-access-token-secret}<\/em>';\n\n$connection = new TwistOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);\n$count = 3;\n$max_length = 25;\n\nfunction get_tweet($screen_name){\n  global $connection, $count, $max_length;\n  $ret = \"\";\n\n\t\/\/ connect\n\t<em>try{<\/em>\n\t\t$user = $connection-&gt;get('statuses\/user_timeline',\n    array('screen_name' =&gt; $screen_name,\n      'count' =&gt; $count,\n      'exclude_replies' =&gt; 'false',\n      'include_rts' =&gt; 'false',)\n    );\n\t<em>} catch (TwistException $e) {\n\t\tfputs(STDERR, \"Error : $screen_name , \" . date(\"Y\/m\/d H:i:s\") . \"\\n\");\n\t\t$text = '&lt;h4&gt;&lt;a href = \"https:\/\/twitter.com\/@' . $screen_name . '\"&gt;@' . $screen_name . '&lt;\/a&gt;&lt;\/h4&gt;';\n\t\t$text .= '&lt;ul class = \"tweet\"&gt;&lt;li&gt;\u53d6\u5f97\u5931\u6557&lt;\/li&gt;&lt;\/ul&gt;' . \"\\n\";\n\t\treturn $text;<\/em>\n\t}\n\n\t\/\/ get user names.\n\t$screen_name = htmlspecialchars($user[0]-&gt;user-&gt;screen_name, ENT_QUOTES, 'UTF-8', false);\n  $names = \"&lt;h4&gt;\" . htmlspecialchars($user[0]-&gt;user-&gt;name, ENT_QUOTES, 'UTF-8', false) \n      . ' &lt;a href = \"https:\/\/twitter.com\/@' . $screen_name . '\"&gt;@' . $screen_name . \"&lt;\/a&gt;&lt;\/h4&gt;\\n\";\n  $ret .= $names;\n\n  $ret .= '&lt;ul class = \"tweet\"&gt;';\n\n  \/\/ get tweets.\n  foreach ($user as $value){\n    $screen_name = htmlspecialchars($value-&gt;user-&gt;screen_name, ENT_QUOTES, 'UTF-8', false);\n    $post_date_utc = htmlspecialchars($value-&gt;created_at, ENT_QUOTES, 'UTF-8', false);\n    $post_date = timezone_change_ja($post_date_utc);\n    $text = htmlspecialchars(mb_substr($value-&gt;text, 0, $max_length, 'UTF-8'), ENT_QUOTES, 'UTF-8', false);\n    $link = '&lt;a href = \"https:\/\/twitter.com\/' . $screen_name . '\/status\/' . $value-&gt;id_str . '\"&gt;';\n    $ret .= \"&lt;li&gt;\" . $post_date . \" \" . $link . $text . \"&lt;\/a&gt;&lt;\/li&gt;\\n\";\n  }\n\n  $ret .= \"&lt;\/ul&gt;\\n\";\n  return $ret;\n}\n\n\/*\n\tTwitter\u304b\u3089\u306e\u30bf\u30a4\u30e0\u30be\u30fc\u30f3\u3092\u65e5\u672c\u6642\u9593(\u6771\u4eac)\u306b\u5909\u63db\u3059\u308bq\n         $time = timezone_change('Tue Jul 12 06:27:46 +0000 2011');\n         echo $time{\"tm_year\"};\n         \n*\/\n\nfunction timezone_change_ja($timezone = null){\n\n\t$year = $month = $day = $hour = $minute = $second = null;\n\tif(!empty($timezone)){\n\n\t\t$date_arr = explode(\" \", $timezone);\n\t\t$year = intval($date_arr[5]);\n\t\t\n\t\tif($date_arr[1] == \"Jan\"){\n\t\t\t$month = 1;\n\t\t}else if($date_arr[1] == \"Feb\"){\n\t\t\t$month = 2;\n\t\t}else if($date_arr[1] == \"Mar\"){\n\t\t\t$month = 3;\n\t\t}else if($date_arr[1] == \"Apr\"){\n\t\t\t$month = 4;\n\t\t}else if($date_arr[1] == \"May\"){\n\t\t\t$month = 5;\n\t\t}else if($date_arr[1] == \"Jun\"){\n\t\t\t$month = 6;\n\t\t}else if($date_arr[1] == \"Jul\"){\n\t\t\t$month = 7;\n\t\t}else if($date_arr[1] == \"Aug\"){\n\t\t\t$month = 8;\n\t\t}else if($date_arr[1] == \"Sep\"){\n\t\t\t$month = 9;\n\t\t}else if($date_arr[1] == \"Oct\"){\n\t\t\t$month = 10;\n\t\t}else if($date_arr[1] == \"Nov\"){\n\t\t\t$month = 11;\n\t\t}else if($date_arr[1] == \"Dec\"){\n\t\t\t$month = 12;\n\t\t}\n\n\t\t$day = intval(sprintf(\"%d\", $date_arr[2]));\n\n\t\t$arr = explode(\":\", $date_arr[3]);\n\t\t\n\t\t$hour = intval(sprintf(\"%d\", $arr[0]));\n\t\t$minute = intval(sprintf(\"%d\", $arr[1]));\n\t\t$second = intval(sprintf(\"%d\", $arr[2]));\n\n\t\t$time = mktime($hour, $minute, $second, $month, $day, $year);\n\t\t$time = $time + 60 * 60 * 9; # 9\u6642\u9593\u9032\u3081\u308b\n    \/\/$date = localtime($time, true);\n    return date(\"Y-m-d H:i\", $time);\n\t\t\/\/return $date;\n\t}else{\n                  return false;\n         }\n}\n\n?&gt;<\/code><\/pre><\/blockquote>\n\n\n\n<p>\u53d6\u5f97\u5931\u6557\u306e\u4f8b\u5916\u767a\u751f\u6642\u306b\u3001\u30b9\u30af\u30ea\u30fc\u30f3\u30cd\u30fc\u30e0\u3068\u300c\u53d6\u5f97\u5931\u6557\u300d\u3092\u623b\u308a\u5024\u306b\u3057\u3066\u8fd4\u3057\u3066\u3001\u6a19\u6e96\u30a8\u30e9\u30fc\u51fa\u529b\u306b\u30a8\u30e9\u30fc\u5185\u5bb9\u3092\u51fa\u529b\u3059\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u305f\u3081 PHP \u306e\u5b9f\u884c\u6587\u3082\u5909\u308f\u308a\u307e\u3059\u3002<br>\u30a8\u30e9\u30fc\u5185\u5bb9\u3092 itawoerror.log \u306b\u8ffd\u8a18\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<blockquote><pre class=\"wp-block-code\"><code>php .\/itawotweet\/itwt_cjpn.php &gt; .\/www\/itawotweet\/itwt_cjpn.html 2&gt;&gt; itawoerror.log<\/code><\/pre><\/blockquote>\n\n\n\n<p>\u30ed\u30b0\u306f\u5b9a\u671f\u7684\u306b\u81ea\u5206\u306e\u30e1\u30fc\u30eb\u30a2\u30c9\u30ec\u30b9\u306b\u9001\u308b\u3088\u3046\u306b\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u66f8\u304d\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<blockquote><pre class=\"wp-block-code\"><code>#!\/bin\/sh\nif [ -s .\/itawoerror.log ]; then\n\tcat -v .\/itawoerror.log | mail -s \"itawotweet error log\" <em>{your-mail-address}<\/em>\n\trm -f itawoerror.log\nfi<\/code><\/pre><\/blockquote>\n\n\n\n<p>\u3053\u308c\u3092 cron \u306b\u767b\u9332\u3057\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300cTwitter API \u3067\u7279\u5b9a\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u30c4\u30a4\u30fc\u30c8\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u300d\u3067\u3059\u304c\u3001\u30bf\u30a4\u30e0\u30a2\u30a6\u30c8\u3057\u3066\u60c5\u5831\u304c\u53d6\u308c\u306a\u3044\u3053\u3068\u304c\u3042\u308a\u3001\u305d\u306e\u8fba\u308a\u3092\u6539\u826f\u3057\u307e\u3057\u305f\u3002 &lt;?php require_once &#8216;TwistOAuth.pha &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/pocolog.bass-world.net\/tech\/2019\/twitter-api-aggregate-tweet-modified\/\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;Twitter API \u3067\u7279\u5b9a\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u306e\u30c4\u30a4\u30fc\u30c8\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u3001\u4fee\u6b63\u7248&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,12,15,16],"tags":[],"class_list":["post-226","post","type-post","status-publish","format-standard","hentry","category-html","category-php","category-twitter","category-wordpress"],"_links":{"self":[{"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/posts\/226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/comments?post=226"}],"version-history":[{"count":0,"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/posts\/226\/revisions"}],"wp:attachment":[{"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/media?parent=226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/categories?post=226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pocolog.bass-world.net\/tech\/wp-json\/wp\/v2\/tags?post=226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}