{"id":1659,"date":"2022-07-31T07:59:09","date_gmt":"2022-07-30T22:59:09","guid":{"rendered":"https:\/\/bacura.jp\/?p=1659"},"modified":"2022-07-31T13:47:38","modified_gmt":"2022-07-31T04:47:38","slug":"twitter%e3%81%a7%e6%b4%bb%e5%8b%95%e3%81%97%e3%81%a6%e3%81%84%e3%81%aa%e3%81%84%e3%83%a6%e3%83%bc%e3%82%b6%e3%83%bc%e3%82%92api%e4%bd%bf%e3%81%a3%e3%81%a6%e3%83%95%e3%82%a9%e3%83%ad%e3%83%bc%e3%81%8b","status":"publish","type":"post","link":"https:\/\/bacura.jp\/?p=1659","title":{"rendered":"Twitter\u3067\u6d3b\u52d5\u3057\u3066\u3044\u306a\u3044\u30e6\u30fc\u30b6\u30fc\u3092API\u4f7f\u3063\u3066\u30d5\u30a9\u30ed\u30fc\u304b\u3089\u5916\u3059"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u3000\u3069\u3046\u3082\u3001\u5409\u5c71\u3067\u3059\u3002\u79c1\u306fTwitter\u3092\u4f7f\u3063\u3066\u304a\u308a\u307e\u3057\u3066\u3001*\u6804\u990a\u58eb\u754c\u9688\u306e\u60c5\u5831\u53ce\u96c6\u306e\u305f\u3081\u306b\u30aa\u30b9\u30b9\u30e1\u306b\u51fa\u3066\u304f\u308b*\u6804\u990a\u58eb\u30e6\u30fc\u30b6\u30fc\u3055\u3093\u3092\u7247\u3063\u7aef\u304b\u3089\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u3044\u307e\u3057\u305f\u3002\u3067\u3001\u7d50\u69cb\u306a\u6570\u306b\u306a\u3063\u3066\u3061\u3087\u3063\u3068\u6574\u7406\u3057\u3088\u3046\u304b\u3068\u601d\u3044\u307e\u3057\u3066\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000\u3053\u3063\u3061\u306f\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u3044\u308b\u306e\u306b\u30d5\u30a9\u30ed\u30fc\u4ed5\u8fd4\u3057\u3066\u304f\u308c\u306a\u3044\u4eba\u306f\u8a31\u305b\u3093\uff01\u30e0\u30ad\u30fc\uff01\u3068\u306a\u308b\u307b\u3069\u30a2\u30ec\u3067\u306f\u306a\u3044\u3067\u3059\u3002\u3068\u308a\u3042\u3048\u305a\u6d3b\u52d5\u3057\u3066\u3044\u306a\u3044\u30e6\u30fc\u30b6\u30fc\u3055\u3093\u306e\u30d5\u30a9\u30ed\u30fc\u306f\u5916\u3057\u3066\u3082\u554f\u984c\u306a\u3044\u3060\u308d\u3046\u3068\u601d\u3044\u6574\u7406\u3092\u59cb\u3081\u305f\u306e\u3067\u3059\u304c\u3001\u624b\u3067\u3044\u3061\u3044\u3061\u3084\u3063\u3066\u3089\u308c\u306a\u3044\u3068\u5373\u609f\u3063\u305f\u306e\u3067\u3001Twitter\u306eAPI\u3092\u4f7f\u3046\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u3000Ruby\u3068Twitter\u306egem\u4f7f\u3063\u3066\u3001API\u30ad\u30fc\u3068\u304b\u306f\u53d6\u5f97\u6e08\u307f\u524d\u63d0\u3067\u3002\u57fa\u672c\u30eb\u30fc\u30eb\u306f\u534a\u5e74\u9593\u30c4\u30a4\u30fc\u30c8\u3057\u3066\u306a\u3044\u30e6\u30fc\u30b6\u30fc\u306f\u30d5\u30a9\u30fc\u30ed\u30fc\u89e3\u9664\u3002\u51cd\u7d50\u30e6\u30fc\u30b6\u30fc\u3078\u306e\u30a2\u30af\u30bb\u30b9\u306f\u30a8\u30e9\u30fc\u3068\u306a\u308b\u305f\u3081\u3001API\u7d4c\u7531\u3067\u30d5\u30a9\u30ed\u30fc\u89e3\u9664\u3067\u304d\u306a\u3044\u30af\u30bd\u4ed5\u69d8\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$API_key = '\u79d8\u5bc6'\n$API_key_secret = '\u79d8\u5bc6'\n$Access_token = '\u79d8\u5bc6'\n$Access_token_secret = '\u79d8\u5bc6'\n\nclient = Twitter::REST::Client.new do |config|\n  config.consumer_key        = $API_key\n  config.consumer_secret     = $API_key_secret\n  config.access_token        = $Access_token\n  config.access_token_secret = $Access_token_secret\nend\n\nc = 1\nlimit_count = 1\n\n#\u81ea\u8eab\u306e\u5404\u30d5\u30a9\u30ed\u30fcID\u3092\u53c2\u7167\u3057\u3066\nclient.follower_ids.each do |fid|\n\n\tbegin\n\n\t\t#\u30d5\u30a9\u30ed\u30fcID\u306e\u76f4\u8fd1\uff11\u30c4\u30a4\u30fc\u30c8\uff08RT\u542b\u3081\u305a\uff09\u3092\u53d6\u5f97\u3057\u3066\n\t\tclient.user_timeline( fid, { :count => 1, :include_rts => false } ).each do |tweet|\n\n\t\t\t#scree_name\u53d6\u5f97\n\t\t\tsn = tweet.user.screen_name\n\n\t\t\t#\u76f4\u8fd1\u30c4\u30a4\u30fc\u30c8\u304b\u3089\u73fe\u5728\u307e\u3067\u4f55\u65e5\u7d4c\u3063\u3066\u3044\u308b\u304b\u8a08\u7b97\n\t\t\tempty_day = (( Time.now - tweet.created_at ) \/ 60 \/ 60 \/ 24 ).to_i\n\n\t\t\t#\u4e00\u5b9a\u671f\u9593\u7d4c\u3063\u3066\u3044\u308c\u3070\u3001\u30d5\u30a9\u30ed\u30fc\u3092\u89e3\u9664\n\t\t\tif empty_day > $threshold\n\t\t\t\tclient.unfollow( sn )\n\n\t\t\t\tputs \"#{sn}:#{empty_day}&#91;\u30d5\u30a9\u30ed\u30fc\u89e3\u9664]\"\n\t  \t\tc += 1\n\t\t\telse\n\t\t\t\tputs \"#{sn}:#{empty_day}\"\n\t\t\tend\n\n\t\t\t#\u30c4\u30a4\u30fc\u30c8\u8aad\u307f\u8fbc\u307fAPI\u5236\u9650\uff08180\uff09\u306b\u8fd1\u3065\u3044\u305f\u3089\u3001\u3057\u3070\u3089\u304f\u5f85\u3064\n\t\t\tif limit_count > 150\n\t\t\t\tputs \"API\u5236\u9650\u306e\u305f\u3081\u300116\u5206\u5f85\u3061\u307e\u3059\"\n\t\t\t\tsleep( 16 * 60 )\n\t\t\t\tlimit_count = 0\n\t\t\tend\n\n\t\t\tlimit_count += 1\n\t\tend\n\n\trescue\n\t\tputs \"#{fid}:ERROR\"\n\t\tlimit_count += 1\n\tend\nend\n\nputs \"#{c - 1}\u4eba\u306e\u30d5\u30a9\u30ed\u30fc\u3092\u89e3\u9664\u3057\u307e\u3057\u305f\"\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u3069\u3046\u3082\u3001\u5409\u5c71\u3067\u3059\u3002\u79c1\u306fTwitter\u3092\u4f7f\u3063\u3066\u304a\u308a\u307e\u3057\u3066\u3001*\u6804\u990a\u58eb\u754c\u9688\u306e\u60c5\u5831\u53ce\u96c6\u306e\u305f\u3081\u306b\u30aa\u30b9\u30b9\u30e1\u306b\u51fa\u3066\u304f\u308b*\u6804\u990a\u58eb\u30e6\u30fc\u30b6\u30fc\u3055\u3093\u3092\u7247\u3063\u7aef\u304b\u3089\u30d5\u30a9\u30ed\u30fc\u3057\u3066\u3044\u307e\u3057\u305f\u3002\u3067\u3001\u7d50\u69cb\u306a\u6570\u306b\u306a\u3063\u3066\u3061\u3087\u3063\u3068\u6574\u7406\u3057\u3088\u3046\u304b\u3068\u601d\u3044\u307e\u3057\u3066\u3002 \u3000\u3053 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1661,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1659","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chat"],"_links":{"self":[{"href":"https:\/\/bacura.jp\/index.php?rest_route=\/wp\/v2\/posts\/1659","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bacura.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bacura.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bacura.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bacura.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1659"}],"version-history":[{"count":6,"href":"https:\/\/bacura.jp\/index.php?rest_route=\/wp\/v2\/posts\/1659\/revisions"}],"predecessor-version":[{"id":1668,"href":"https:\/\/bacura.jp\/index.php?rest_route=\/wp\/v2\/posts\/1659\/revisions\/1668"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bacura.jp\/index.php?rest_route=\/wp\/v2\/media\/1661"}],"wp:attachment":[{"href":"https:\/\/bacura.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bacura.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bacura.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}