Twitterのトレンドワードを「R」で調べる

TwitterAPIにログイン

Twitterからトレンドを調べます。
認証に必要なキーを準備します。

#TwitterAPI認証情報設定。API登録の際に指定された値を指定
consumerKey <- "xxxxxyyyyy"
consumerSecret <- "zzzzzxxxxx"
accessToken <- "yyyyyzzzzz"
accessSecret <- "xxxyyyzzzz"

ログインします。
※APIを使うためにはTwitterへの申請が必要です。

#TwitterAPIにログイン
library("twitteR")
options(httr_oauth_cache = TRUE)
setup_twitter_oauth(consumerKey, consumerSecret, accessToken, accessSecret)
[1] "Using direct authentication"

#「twitteR」パッケージが入ってない場合は先にインストール
install.packages('twitteR')

まず、地域ID(WOEID:Where On Earth IDentifier)を確認します。
このIDを使い、該当するエリアのトレンドワードをピックアップできます。

#Twitter(全体?)から地域名とIDを取得する
#その中から日本のIDだけを抽出
woeid <- availableTrendLocations()

woeid
                    name              country    woeid
1              Worldwide                             1
2               Winnipeg               Canada     2972
3                 Ottawa               Canada     3369
4                 Quebec               Canada     3444
5               Montreal               Canada     3534

#IDリスト一覧は後出

WOEIDを使用

「WOEID = 1」(World)を指定してみます。

#世界のトレンドワード上位10を取得する ※2022/11/05 01時少し過ぎ
#「$name」とすることでワードだけに指定できる
trends_world <- getTrends(1)
trends_world$name %>% head(10)
 [1] "キンプリ"                    "ジャニーズ"                 
 [3] "Drake"                       "推しの日"                   
 [5] "#渡辺翔太誕生祭2022"         "タッキー"                   
 [7] "ショック"                    "#My_youth_Q_birthday"       
 [9] "平野紫耀"                    "#민들레같이_피어난_창민이날"

#「Montreal」の場合は「3534」を指定
trends_montreal <- getTrends(3534)
trends_montreal$name %>% head(10)
 [1] "Drake"           "CUPE"            "#WarcraftStory"  "Ford"           
 [5] "Ford"            "#HerLoss"        "#39kIsNotEnough" "Kyrie"          
 [9] "#onpoli"         "#TwitterLayoffs"

日本(Japan)の都市をピックアップします。

woeid %>% filter(country == "Japan")
         name country    woeid
1  Kitakyushu   Japan  1110809
2     Saitama   Japan  1116753
3       Chiba   Japan  1117034
4     Fukuoka   Japan  1117099
5   Hamamatsu   Japan  1117155
6   Hiroshima   Japan  1117227
7    Kawasaki   Japan  1117502
8        Kobe   Japan  1117545
9    Kumamoto   Japan  1117605
10     Nagoya   Japan  1117817
11    Niigata   Japan  1117881
12 Sagamihara   Japan  1118072
13    Sapporo   Japan  1118108
14     Sendai   Japan  1118129
15  Takamatsu   Japan  1118285
16      Tokyo   Japan  1118370
17   Yokohama   Japan  1118550
18    Okinawa   Japan  2345896
19      Osaka   Japan 15015370
20      Kyoto   Japan 15015372
21      Japan   Japan 23424856
22    Okayama   Japan 90036018

「TOKYO = 1118370」を指定してみます。

#東京のトレンドワード
trends_tokyo <- getTrends(1118370)
trends_tokyo$name %>% head(10)
 [1] "#BiSHリズムライブ" "ジャイアン"        "Wordle 504"        "#bananamoon"      
 [5] "神宮寺の3人"       "#永瀬廉"           "The Birthday"      "キンプリ"         
 [9] "ジャニーズ"        "推しの日"    

WOEID一覧

woeid
                    name              country    woeid
1              Worldwide                             1
2               Winnipeg               Canada     2972
3                 Ottawa               Canada     3369
4                 Quebec               Canada     3444
5               Montreal               Canada     3534
6                Toronto               Canada     4118
7               Edmonton               Canada     8676
8                Calgary               Canada     8775
9              Vancouver               Canada     9807
10            Birmingham       United Kingdom    12723
11             Blackpool       United Kingdom    12903
12           Bournemouth       United Kingdom    13383
13              Brighton       United Kingdom    13911
14               Bristol       United Kingdom    13963
15               Cardiff       United Kingdom    15127
16              Coventry       United Kingdom    17044
17                 Derby       United Kingdom    18114
18             Edinburgh       United Kingdom    19344
19               Glasgow       United Kingdom    21125
20                  Hull       United Kingdom    25211
21                 Leeds       United Kingdom    26042
22             Leicester       United Kingdom    26062
23             Liverpool       United Kingdom    26734
24            Manchester       United Kingdom    28218
25         Middlesbrough       United Kingdom    28869
26             Newcastle       United Kingdom    30079
27            Nottingham       United Kingdom    30720
28              Plymouth       United Kingdom    32185
29            Portsmouth       United Kingdom    32452
30               Preston       United Kingdom    32566
31             Sheffield       United Kingdom    34503
32        Stoke-on-Trent       United Kingdom    36240
33               Swansea       United Kingdom    36758
34                London       United Kingdom    44418
35               Belfast       United Kingdom    44544
36         Santo Domingo   Dominican Republic    76456
37        Guatemala City            Guatemala    83123
38              Acapulco               Mexico   110978
39        Aguascalientes               Mexico   111579
40             Chihuahua               Mexico   115958
41           Mexico City               Mexico   116545
42         Ciudad Juarez               Mexico   116556
43        Nezahualcóyotl               Mexico   116564
44              Culiacán               Mexico   117994
45   Ecatepec de Morelos               Mexico   118466
46           Guadalajara               Mexico   124162
47            Hermosillo               Mexico   124785
48                  León               Mexico   131068
49                Mérida               Mexico   133327
50              Mexicali               Mexico   133475
51             Monterrey               Mexico   134047
52               Morelia               Mexico   134091
53   Naucalpan de Juárez               Mexico   134395
54                Puebla               Mexico   137612
55             Querétaro               Mexico   138045
56              Saltillo               Mexico   141272
57       San Luis Potosí               Mexico   144265
58               Tijuana               Mexico   149361
59                Toluca               Mexico   149769
60               Zapopan               Mexico   151582
61               Mendoza            Argentina   332471
62              Santiago                Chile   349859
63            Concepcion                Chile   349860
64            Valparaiso                Chile   349861
65                Bogotá             Colombia   368148
66                  Cali             Colombia   368149
67              Medellín             Colombia   368150
68          Barranquilla             Colombia   368151
69                 Quito              Ecuador   375732
70             Guayaquil              Ecuador   375733
71               Caracas            Venezuela   395269
72             Maracaibo            Venezuela   395270
73               Maracay            Venezuela   395271
74              Valencia            Venezuela   395272
75             Barcelona            Venezuela   395273
76        Ciudad Guayana            Venezuela   395275
77               Turmero            Venezuela   395277
78                  Lima                 Peru   418440
79              Brasília               Brazil   455819
80                 Belém               Brazil   455820
81        Belo Horizonte               Brazil   455821
82              Curitiba               Brazil   455822
83          Porto Alegre               Brazil   455823
84                Recife               Brazil   455824
85        Rio de Janeiro               Brazil   455825
86              Salvador               Brazil   455826
87             São Paulo               Brazil   455827
88              Campinas               Brazil   455828
89             Fortaleza               Brazil   455830
90               Goiânia               Brazil   455831
91                Manaus               Brazil   455833
92              São Luís               Brazil   455834
93             Guarulhos               Brazil   455867
94               Córdoba            Argentina   466861
95               Rosario            Argentina   466862
96          Barquisimeto            Venezuela   468382
97               Maturín            Venezuela   468384
98          Buenos Aires            Argentina   468739
99                Gdańsk               Poland   493417
100               Kraków               Poland   502075
101                 Lodz               Poland   505120
102               Poznań               Poland   514048
103               Warsaw               Poland   523920
104              Wroclaw               Poland   526363
105               Vienna              Austria   551801
106                 Cork              Ireland   560472
107               Dublin              Ireland   560743
108               Galway              Ireland   560912
109             Bordeaux               France   580778
110                Lille               France   608105
111                 Lyon               France   609125
112            Marseille               France   610264
113          Montpellier               France   612977
114               Nantes               France   613858
115                Paris               France   615702
116               Rennes               France   619163
117           Strasbourg               France   627791
118             Toulouse               France   628886
119               Berlin              Germany   638242
120               Bremen              Germany   641142
121             Dortmund              Germany   645458
122              Dresden              Germany   645686
123           Dusseldorf              Germany   646099
124                Essen              Germany   648820
125            Frankfurt              Germany   650272
126              Hamburg              Germany   656958
127              Cologne              Germany   667931
128              Leipzig              Germany   671072
129               Munich              Germany   676757
130            Stuttgart              Germany   698064
131              Bologna                Italy   711080
132                Genoa                Italy   716085
133                Milan                Italy   718345
134               Naples                Italy   719258
135              Palermo                Italy   719846
136                 Rome                Italy   721943
137                Turin                Italy   725003
138             Den Haag          Netherlands   726874
139            Amsterdam          Netherlands   727232
140            Rotterdam          Netherlands   733075
141              Utrecht          Netherlands   734047
142            Barcelona                Spain   753692
143               Bilbao                Spain   754542
144           Las Palmas                Spain   764814
145               Madrid                Spain   766273
146               Malaga                Spain   766356
147               Murcia                Spain   768026
148                Palma                Spain   769293
149              Seville                Spain   774508
150             Valencia                Spain   776688
151             Zaragoza                Spain   779063
152               Geneva          Switzerland   782538
153             Lausanne          Switzerland   783058
154               Zurich          Switzerland   784794
155                Brest              Belarus   824382
156               Grodno              Belarus   825848
157                Gomel              Belarus   825978
158                Minsk              Belarus   834463
159                 Riga               Latvia   854823
160               Bergen               Norway   857105
161                 Oslo               Norway   862592
162           Gothenburg               Sweden   890869
163            Stockholm               Sweden   906057
164       Dnipropetrovsk              Ukraine   918981
165              Donetsk              Ukraine   919163
166              Kharkiv              Ukraine   922137
167                 Kyiv              Ukraine   924938
168                 Lviv              Ukraine   924943
169                Odesa              Ukraine   929398
170           Zaporozhye              Ukraine   939628
171               Athens               Greece   946738
172         Thessaloniki               Greece   963291
173               Bekasi            Indonesia  1030077
174                Depok            Indonesia  1032539
175            Pekanbaru            Indonesia  1040779
176             Surabaya            Indonesia  1044316
177             Makassar            Indonesia  1046138
178              Bandung            Indonesia  1047180
179              Jakarta            Indonesia  1047378
180                Medan            Indonesia  1047908
181            Palembang            Indonesia  1048059
182             Semarang            Indonesia  1048324
183            Tangerang            Indonesia  1048536
184            Singapore            Singapore  1062617
185                Perth            Australia  1098081
186             Adelaide            Australia  1099805
187             Brisbane            Australia  1100661
188             Canberra            Australia  1100968
189               Darwin            Australia  1101597
190            Melbourne            Australia  1103816
191               Sydney            Australia  1105779
192           Kitakyushu                Japan  1110809
193              Saitama                Japan  1116753
194                Chiba                Japan  1117034
195              Fukuoka                Japan  1117099
196            Hamamatsu                Japan  1117155
197            Hiroshima                Japan  1117227
198             Kawasaki                Japan  1117502
199                 Kobe                Japan  1117545
200             Kumamoto                Japan  1117605
201               Nagoya                Japan  1117817
202              Niigata                Japan  1117881
203           Sagamihara                Japan  1118072
204              Sapporo                Japan  1118108
205               Sendai                Japan  1118129
206            Takamatsu                Japan  1118285
207                Tokyo                Japan  1118370
208             Yokohama                Japan  1118550
209               Goyang                Korea  1130853
210               Yongin                Korea  1132094
211                Ansan                Korea  1132444
212              Bucheon                Korea  1132445
213                Busan                Korea  1132447
214             Changwon                Korea  1132449
215                Daegu                Korea  1132466
216              Gwangju                Korea  1132481
217              Incheon                Korea  1132496
218             Seongnam                Korea  1132559
219                Suwon                Korea  1132567
220                Ulsan                Korea  1132578
221                Seoul                Korea  1132599
222               Kajang             Malaysia  1141268
223                 Ipoh             Malaysia  1154679
224          Johor Bahru             Malaysia  1154698
225                Klang             Malaysia  1154726
226         Kuala Lumpur             Malaysia  1154781
227              Calocan          Philippines  1167715
228               Makati          Philippines  1180689
229                Pasig          Philippines  1187115
230               Taguig          Philippines  1195098
231             Antipolo          Philippines  1198785
232       Cagayan de Oro          Philippines  1199002
233            Cebu City          Philippines  1199079
234           Davao City          Philippines  1199136
235               Manila          Philippines  1199477
236          Quezon City          Philippines  1199682
237       Zamboanga City          Philippines  1199980
238              Bangkok             Thailand  1225448
239                Hanoi              Vietnam  1236594
240            Hai Phong              Vietnam  1236690
241              Can Tho              Vietnam  1252351
242              Da Nang              Vietnam  1252376
243     Ho Chi Minh City              Vietnam  1252431
244              Algiers              Algeria  1253079
245                Accra                Ghana  1326075
246               Kumasi                Ghana  1330595
247           Benin City              Nigeria  1387660
248               Ibadan              Nigeria  1393672
249               Kaduna              Nigeria  1396439
250                 Kano              Nigeria  1396803
251                Lagos              Nigeria  1398823
252        Port Harcourt              Nigeria  1404447
253                 Giza                Egypt  1521643
254                Cairo                Egypt  1521894
255           Alexandria                Egypt  1522006
256              Mombasa                Kenya  1528335
257              Nairobi                Kenya  1528488
258               Durban         South Africa  1580913
259         Johannesburg         South Africa  1582504
260       Port Elizabeth         South Africa  1586614
261             Pretoria         South Africa  1586638
262               Soweto         South Africa  1587677
263            Cape Town         South Africa  1591691
264               Medina         Saudi Arabia  1937801
265               Dammam         Saudi Arabia  1939574
266               Riyadh         Saudi Arabia  1939753
267               Jeddah         Saudi Arabia  1939873
268                Mecca         Saudi Arabia  1939897
269              Sharjah United Arab Emirates  1940119
270            Abu Dhabi United Arab Emirates  1940330
271                Dubai United Arab Emirates  1940345
272                Haifa               Israel  1967449
273             Tel Aviv               Israel  1968212
274            Jerusalem               Israel  1968222
275                Amman               Jordan  1968902
276          Chelyabinsk               Russia  1997422
277           Khabarovsk               Russia  2018708
278            Krasnodar               Russia  2028717
279          Krasnoyarsk               Russia  2029043
280               Samara               Russia  2077746
281             Voronezh               Russia  2108210
282        Yekaterinburg               Russia  2112237
283              Irkutsk               Russia  2121040
284                Kazan               Russia  2121267
285               Moscow               Russia  2122265
286      Nizhny Novgorod               Russia  2122471
287          Novosibirsk               Russia  2122541
288                 Omsk               Russia  2122641
289                 Perm               Russia  2122814
290        Rostov-on-Don               Russia  2123177
291     Saint Petersburg               Russia  2123260
292                  Ufa               Russia  2124045
293          Vladivostok               Russia  2124288
294            Volgograd               Russia  2124298
295              Karachi             Pakistan  2211096
296               Lahore             Pakistan  2211177
297               Multan             Pakistan  2211269
298           Rawalpindi             Pakistan  2211387
299           Faisalabad             Pakistan  2211574
300               Muscat                 Oman  2268284
301               Nagpur                India  2282863
302              Lucknow                India  2295377
303               Kanpur                India  2295378
304                Patna                India  2295381
305               Ranchi                India  2295383
306              Kolkata                India  2295386
307             Srinagar                India  2295387
308             Amritsar                India  2295388
309               Jaipur                India  2295401
310            Ahmedabad                India  2295402
311               Rajkot                India  2295404
312                Surat                India  2295405
313               Bhopal                India  2295407
314               Indore                India  2295408
315                Thane                India  2295410
316               Mumbai                India  2295411
317                 Pune                India  2295412
318            Hyderabad                India  2295414
319            Bangalore                India  2295420
320              Chennai                India  2295424
321               Mersin               Turkey  2323778
322                Adana               Turkey  2343678
323               Ankara               Turkey  2343732
324              Antalya               Turkey  2343733
325                Bursa               Turkey  2343843
326           Diyarbakır               Turkey  2343932
327            Eskişehir               Turkey  2343980
328            Gaziantep               Turkey  2343999
329             Istanbul               Turkey  2344116
330                Izmir               Turkey  2344117
331              Kayseri               Turkey  2344174
332                Konya               Turkey  2344210
333              Okinawa                Japan  2345896
334              Daejeon                Korea  2345975
335             Auckland          New Zealand  2348079
336          Albuquerque        United States  2352824
337              Atlanta        United States  2357024
338               Austin        United States  2357536
339            Baltimore        United States  2358820
340          Baton Rouge        United States  2359991
341           Birmingham        United States  2364559
342               Boston        United States  2367105
343            Charlotte        United States  2378426
344              Chicago        United States  2379574
345           Cincinnati        United States  2380358
346            Cleveland        United States  2381475
347     Colorado Springs        United States  2383489
348             Columbus        United States  2383660
349     Dallas-Ft. Worth        United States  2388929
350               Denver        United States  2391279
351              Detroit        United States  2391585
352              El Paso        United States  2397816
353               Fresno        United States  2407517
354           Greensboro        United States  2414469
355           Harrisburg        United States  2418046
356             Honolulu        United States  2423945
357              Houston        United States  2424766
358         Indianapolis        United States  2427032
359              Jackson        United States  2428184
360         Jacksonville        United States  2428344
361          Kansas City        United States  2430683
362            Las Vegas        United States  2436704
363           Long Beach        United States  2441472
364          Los Angeles        United States  2442047
365           Louisville        United States  2442327
366              Memphis        United States  2449323
367                 Mesa        United States  2449808
368                Miami        United States  2450022
369            Milwaukee        United States  2451822
370          Minneapolis        United States  2452078
371            Nashville        United States  2457170
372            New Haven        United States  2458410
373          New Orleans        United States  2458833
374             New York        United States  2459115
375              Norfolk        United States  2460389
376        Oklahoma City        United States  2464592
377                Omaha        United States  2465512
378              Orlando        United States  2466256
379         Philadelphia        United States  2471217
380              Phoenix        United States  2471390
381           Pittsburgh        United States  2473224
382             Portland        United States  2475687
383           Providence        United States  2477058
384              Raleigh        United States  2478307
385             Richmond        United States  2480894
386           Sacramento        United States  2486340
387            St. Louis        United States  2486982
388       Salt Lake City        United States  2487610
389          San Antonio        United States  2487796
390            San Diego        United States  2487889
391        San Francisco        United States  2487956
392             San Jose        United States  2488042
393              Seattle        United States  2490383
394          Tallahassee        United States  2503713
395                Tampa        United States  2503863
396               Tucson        United States  2508428
397       Virginia Beach        United States  2512636
398           Washington        United States  2514815
399                Osaka                Japan 15015370
400                Kyoto                Japan 15015372
401                Delhi                India 20070458
402 United Arab Emirates United Arab Emirates 23424738
403              Algeria              Algeria 23424740
404            Argentina            Argentina 23424747
405            Australia            Australia 23424748
406              Austria              Austria 23424750
407              Bahrain              Bahrain 23424753
408              Belgium              Belgium 23424757
409              Belarus              Belarus 23424765
410               Brazil               Brazil 23424768
411               Canada               Canada 23424775
412                Chile                Chile 23424782
413             Colombia             Colombia 23424787
414              Denmark              Denmark 23424796
415   Dominican Republic   Dominican Republic 23424800
416              Ecuador              Ecuador 23424801
417                Egypt                Egypt 23424802
418              Ireland              Ireland 23424803
419               France               France 23424819
420                Ghana                Ghana 23424824
421              Germany              Germany 23424829
422               Greece               Greece 23424833
423            Guatemala            Guatemala 23424834
424            Indonesia            Indonesia 23424846
425                India                India 23424848
426               Israel               Israel 23424852
427                Italy                Italy 23424853
428                Japan                Japan 23424856
429               Jordan               Jordan 23424860
430                Kenya                Kenya 23424863
431                Korea                Korea 23424868
432               Kuwait               Kuwait 23424870
433              Lebanon              Lebanon 23424873
434               Latvia               Latvia 23424874
435                 Oman                 Oman 23424898
436               Mexico               Mexico 23424900
437             Malaysia             Malaysia 23424901
438              Nigeria              Nigeria 23424908
439          Netherlands          Netherlands 23424909
440               Norway               Norway 23424910
441          New Zealand          New Zealand 23424916
442                 Peru                 Peru 23424919
443             Pakistan             Pakistan 23424922
444               Poland               Poland 23424923
445               Panama               Panama 23424924
446             Portugal             Portugal 23424925
447                Qatar                Qatar 23424930
448          Philippines          Philippines 23424934
449          Puerto Rico          Puerto Rico 23424935
450               Russia               Russia 23424936
451         Saudi Arabia         Saudi Arabia 23424938
452         South Africa         South Africa 23424942
453            Singapore            Singapore 23424948
454                Spain                Spain 23424950
455               Sweden               Sweden 23424954
456          Switzerland          Switzerland 23424957
457             Thailand             Thailand 23424960
458               Turkey               Turkey 23424969
459       United Kingdom       United Kingdom 23424975
460              Ukraine              Ukraine 23424976
461        United States        United States 23424977
462            Venezuela            Venezuela 23424982
463              Vietnam              Vietnam 23424984
464             Petaling             Malaysia 56013632
465          Hulu Langat             Malaysia 56013645
466                 Ahsa         Saudi Arabia 56120136
467              Okayama                Japan 90036018
タイトルとURLをコピーしました