소개
X API 시작하기
R 환경 설정하기
환경 변수 설정하기
요청 보내기
readline 메서드를 사용하세요. 조회하려는 핸들을 입력한 뒤 $USERNAME을 원하는 X 핸들로 교체하여, 정의한 핸들이 URL에 포함되도록 구성합니다.
JSON 페이로드 다루기
print 대신 cat을 사용하세요.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Sys.setenv(BEARER_TOKEN = "your-bearer-token")
install.packages("httr")
install.packages("jsonlite")
install.packages("dplyr")
require(httr)
require(jsonlite)
require(dplyr)
bearer_token <- Sys.getenv("$BEARER_TOKEN")
headers <- c(`Authorization` = sprintf('Bearer %s', bearer_token))
params <- list(`user.fields` = 'description', `expansions` = 'pinned_tweet_id')
readline 메서드를 사용하세요. 조회하려는 핸들을 입력한 뒤 $USERNAME을 원하는 X 핸들로 교체하여, 정의한 핸들이 URL에 포함되도록 구성합니다.
handle <- readline('$USERNAME')
url_handle <- sprintf('https://api.x.com/2/users/by?usernames=%s', handle)
response <-
httr::GET(url = url_handle,
httr::add_headers(.headers = headers),
query = params)
obj <- httr::content(response, as = "text")
print(obj)
json_data <- fromJSON(obj, flatten = TRUE) %>% as.data.frame View(json_data)
final <-
sprintf(
"Handle: %s\nBio: %s\nPinned Post: %s",
json_data$data.username,
json_data$data.description,
json_data$includes.tweets.text
)
print 대신 cat을 사용하세요.
cat(final)