23
loading...
This website collects cookies to deliver better user experience
Using recent Tweet counts, any developer can get the counts (volume) of Tweets from the last 7 days
Using full-archive Tweet counts, academic researchers can get the counts of Tweets from the full-archive of public Tweets
pip3 install plotly
pip3 install twarc
import plotly.graph_objects as go
from twarc import Twarc2
import json
# Replace with your own bearer token
client = Twarc2(
bearer_token="REPLACE_ME")
# Replace the query below with your own query
query = "#TwitterAPI"
# Get the recent Tweet counts using Twarc for your query by day
search_results = client.counts_recent(query=query, granularity='day')
for page in search_results:
# Get the data object from the Tweet counts response which contains the daily Tweet count
data = page['data']
break
print(json.dumps(data, indent=2))
[
{
"end": "2021-07-02T00:00:00.000Z",
"start": "2021-07-01T22:57:15.000Z",
"tweet_count": 1
},
{
"end": "2021-07-03T00:00:00.000Z",
"start": "2021-07-02T00:00:00.000Z",
"tweet_count": 36
},
{
"end": "2021-07-04T00:00:00.000Z",
"start": "2021-07-03T00:00:00.000Z",
"tweet_count": 9
},
{
"end": "2021-07-05T00:00:00.000Z",
"start": "2021-07-04T00:00:00.000Z",
"tweet_count": 4
},
{
"end": "2021-07-06T00:00:00.000Z",
"start": "2021-07-05T00:00:00.000Z",
"tweet_count": 5
},
{
"end": "2021-07-07T00:00:00.000Z",
"start": "2021-07-06T00:00:00.000Z",
"tweet_count": 12
},
{
"end": "2021-07-08T00:00:00.000Z",
"start": "2021-07-07T00:00:00.000Z",
"tweet_count": 7
},
{
"end": "2021-07-08T22:57:15.000Z",
"start": "2021-07-08T00:00:00.000Z",
"tweet_count": 10
}
]
day = []
tweet_counts = []
for d in data:
# Add the start date to display on x-axis
day.append(d['start'][:10])
# Add the daily Tweet counts to display on the y-axis
tweet_counts.append(d['tweet_count'])
# Build a bar chart
fig = go.Figure(data=[go.Bar(x=day, y=tweet_counts)])
# Add the titles
fig.update_layout(xaxis_title="Time Period", yaxis_title="Tweet Counts",
title_text='Tweets by day for {}'.format(query))
fig.show()
import plotly.graph_objects as go
from twarc import Twarc2
import json
# Replace with your own bearer token
client = Twarc2(bearer_token="XXXXX")
# Replace the query below with your own query
query = "#TwitterAPI"
# Get the recent Tweet counts using Twarc for your query by day
search_results = client.counts_recent(query=query, granularity='day')
for page in search_results:
# Get the data object from the Tweet counts response which contains the daily Tweet count
data = page['data']
break
print(json.dumps(data, indent=2))
day = []
tweet_counts = []
for d in data:
# Add the start date to display on x-axis
day.append(d['start'][:10])
# Add the daily Tweet counts to display on the y-axis
tweet_counts.append(d['tweet_count'])
# Build a bar chart
fig = go.Figure(data=[go.Bar(x=day, y=tweet_counts)])
# Add the titles
fig.update_layout(xaxis_title="Time Period", yaxis_title="Tweet Counts",
title_text='Tweets by day for {}'.format(query))
fig.show()