i need help working with Twitch API

I need help pullin data from twitch api. Im trying to get a list of streamers and follower count. i keep getting a error message
Username: punkdagod Follower Count:
Username: Myth Follower Count:
Username: user3 Follower Count:
Error in is.na(output) || !is.character(output) :
'length = 3' in coercion to 'logical(1)'

https://id.twitch.tv/oauth2/token
Error: unexpected '/' in "https:/"
here's the code
I keep getting this error message and im not really sure why
Username: punkdagod Follower Count:
Username: Myth Follower Count:
Username: user3 Follower Count:
Error in is.na(output) || !is.character(output) :
'length = 3' in coercion to 'logical(1)'


install.packages("httr")
install.packages("jsonlite")

library(httr)
library(jsonlite)

Set the URL for the Twitch API endpoint

user_url <- "url link"
follower_url <- "follower url link"

Set the usernames for which you want to retrieve follower counts

usernames <- c("punkdagod", "Myth") # Add more usernames as needed

Initialize an empty list to store the follower counts

follower_counts <- list()

Get the access token using client credentials flow

token_url <- "https://id.twitch.tv/oauth2/token"
token_params <- list(
client_id = client_id,
client_secret = client_secret,
grant_type = "client_credentials"
)
response <- POST(token_url, body = token_params, encode = "form")
token_data <- content(response, as = "parsed")
access_token <- token_data$access_token

Set the headers for the API requests, including the access token

headers <- c(
"Client-ID" = client_id,
"Authorization" = paste("Bearer", access_token)
)

Loop through each username and retrieve the follower count

for (username in usernames) {

Get user ID for the username

user_params <- list(login = username)
response <- GET(user_url, query = user_params, add_headers(.headers = headers))
user_data <- content(response, as = "parsed")
user_id <- user_data$data[[1]]$id

Get follower count for the user

follower_params <- list(to_id = user_id)
response <- GET(follower_url, query = follower_params, add_headers(.headers = headers))
follower_data <- content(response, as = "parsed")
follower_count <- follower_data$total

Store follower count in the list

follower_counts[[username]] <- follower_count
}

Print the follower counts

for (username in usernames) {
follower_count <- follower_counts[[username]]
cat("Username:", username, "Follower Count:", follower_count, "\n")
}

I tried restarting the program and reinstalling the packages and rerunning it. i also changed the url for the end point but i am stumped

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.