Please help. I am doing my final college project about research regarding 2019 Presidential Election in Indonesia. I use data from Twitter to predict the results of the election. I want to extract tweets every 2 weeks from September 2018 to January 2019, but I cannot collect tweets past 7 days from now. So I apply for developer account to use the full archive search API to collect tweets from September 2018. My developer account already approved, I already create an app, and I already set the dev environment to my app. But I still cannot extract tweets past 7 days from now using my old code. So I search the solution and I found this code :
library(jsonlite)
#Create your own appication key at https://dev.twitter.com/apps
consumer_key = "insert_consumer_key";
consumer_secret = "insert_consumer_secret";
#Use basic auth
secret <- jsonlite::base64_enc(paste(consumer_key, consumer_secret, sep = ":"))
req <- httr::POST("https://api.twitter.com/oauth2/token",
httr::add_headers(
"Authorization" = paste("Basic", gsub("\n", "", secret)),
"Content-Type" = "application/x-www-form-urlencoded;charset=UTF-8"
),
body = "grant_type=client_credentials"
);
#Extract the access token
httr::stop_for_status(req, "authenticate with twitter")
token <- paste("Bearer", httr::content(req)$access_token)
#Actual API call
url <- "https://api.twitter.com/1.1/statuses/user_timeline.json?count=10&screen_name=Rbloggers"
req <- httr::GET(url, httr::add_headers(Authorization = token))
json <- httr::content(req, as = "text")
tweets <- fromJSON(json)
substring(tweets$text, 1, 100)
So I change the customer key and secret for my own and the url, and it will be like this :
library(jsonlite)
#Create your own appication key at https://dev.twitter.com/apps
consumer_key = "my_consumer_key";
consumer_secret = "my_consumer_secret";
#Use basic auth
secret <- jsonlite::base64_enc(paste(consumer_key, consumer_secret, sep = ":"))
req <- httr::POST("https://api.twitter.com/oauth2/token",
httr::add_headers(
"Authorization" = paste("Basic", gsub("\n", "", secret)),
"Content-Type" = "application/x-www-form-urlencoded;charset=UTF-8"
),
body = "grant_type=client_credentials"
);
#Extract the access token
httr::stop_for_status(req, "authenticate with twitter")
token <- paste("Bearer", httr::content(req)$access_token)
#Actual API call
url <- "https://api.twitter.com/1.1/tweets/search/fullarchive/my_env_label.json"
req <- httr::GET(url, httr::add_headers(Authorization = token))
json <- httr::content(req, as = "text")
tweets <- fromJSON(json)
substring(tweets$text, 1, 100)
But when I run the code, nothing happen and only show this :
character(0)
So I try to change the url with the query like this :
url <- "https://api.twitter.com/1.1/tweets/search/fullarchive/my_env_label.json?query=%23JokowiLagi&fromDate=201809270000&toDate=201810010000"
But still nothing happen and the result is same as before. The only difference is this time my subscriptions details are reduced.
So please help me, tell me what I should do to solve this problem.
Thank you.
(Note : I am using R programming language to extract the data from Twitter and to run the above codes)