R에서 Twitter Oauth를 이용하여 접속하기 (트위터 인증)

CODEDRAGON Development/Big Data, R, ...

반응형


 

 

R에서 Twitter Oauth를 이용하여 접속하기

 

twitteR 패키지 설치하기

http://codedragon.tistory.com/5008

 

> library(twitteR)

>

library(twitteR)라고 되어 있습니다. library는 괄호 안의 파일을 불러오는데요. twitteR을 불러오는 것입니다.

twitteR 패키지는 R 프로그래밍 언어 패키지 중 하나로 twitter API에 접속해서 정보처리를 합니다.

 

 

newest version of the twitteR package from github 설치

> install.packages(c("devtools", "rjson", "bit64", "httr"))

C:/Users/codedragon/Documents/R/win-library/3.3’의 위치에 패키지() 설치합니다.

(왜냐하면 lib’가 지정되지 않았기 때문입니다)

memoise, whisker, digest, rstudioapi, git2r, withr() 또한 설치합니다.

 

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/memoise_1.0.0.zip' 시도합니다

Content type 'application/zip' length 23296 bytes (22 KB)

downloaded 22 KB

 

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/whisker_0.3-2.zip' 시도합니다

Content type 'application/zip' length 64739 bytes (63 KB)

downloaded 63 KB

 

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/digest_0.6.12.zip' 시도합니다

Content type 'application/zip' length 172726 bytes (168 KB)

downloaded 168 KB

 

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/rstudioapi_0.6.zip' 시도합니다

Content type 'application/zip' length 50711 bytes (49 KB)

downloaded 49 KB

 

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/git2r_0.18.0.zip' 시도합니다

Content type 'application/zip' length 3045931 bytes (2.9 MB)

downloaded 2.9 MB

 

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/withr_1.0.2.zip' 시도합니다

Content type 'application/zip' length 42243 bytes (41 KB)

downloaded 41 KB

 

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/devtools_1.12.0.zip' 시도합니다

Content type 'application/zip' length 432270 bytes (422 KB)

downloaded 422 KB

 

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/rjson_0.2.15.zip' 시도합니다

Content type 'application/zip' length 561644 bytes (548 KB)

downloaded 548 KB

 

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/bit64_0.9-5.zip' 시도합니다

Content type 'application/zip' length 493973 bytes (482 KB)

downloaded 482 KB

 

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/httr_1.2.1.zip' 시도합니다

Content type 'application/zip' length 282147 bytes (275 KB)

downloaded 275 KB

 

패키지 memoise’를 성공적으로 압축해제하였고 MD5 sums 확인되었습니다

패키지 whisker’를 성공적으로 압축해제하였고 MD5 sums 확인되었습니다

패키지 digest’를 성공적으로 압축해제하였고 MD5 sums 확인되었습니다

패키지 rstudioapi’를 성공적으로 압축해제하였고 MD5 sums 확인되었습니다

패키지 git2r’를 성공적으로 압축해제하였고 MD5 sums 확인되었습니다

패키지 withr’를 성공적으로 압축해제하였고 MD5 sums 확인되었습니다

패키지 devtools’를 성공적으로 압축해제하였고 MD5 sums 확인되었습니다

패키지 rjson’를 성공적으로 압축해제하였고 MD5 sums 확인되었습니다

경고: 패키지 rjson’의 이전설치를 삭제할 없습니다

패키지 bit64’를 성공적으로 압축해제하였고 MD5 sums 확인되었습니다

경고: 패키지 bit64’의 이전설치를 삭제할 없습니다

패키지 httr’를 성공적으로 압축해제하였고 MD5 sums 확인되었습니다

 

다운로드된 바이너리 패키지들은 다음의 위치에 있습니다

        C:\Users\Public\Documents\ESTsoft\CreatorTemp\Rtmpi61v46\downloaded_packages

> library(devtools)

> install_github("twitteR", username="geoffjentry")

Downloading GitHub repo geoffjentry/twitteR@master

from URL https://api.github.com/repos/geoffjentry/twitteR/zipball/master

Installing twitteR

Installing 1 package: bit64

Installing package into C:/Users/codedragon/Documents/R/win-library/3.3

(as lib is unspecified)

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/bit64_0.9-5.zip' 시도합니다

Content type 'application/zip' length 493973 bytes (482 KB)

downloaded 482 KB

 

package bit64 successfully unpacked and MD5 sums checked

경고: cannot remove prior installation of package bit64

 

The downloaded binary packages are in

        C:\Users\Public\Documents\ESTsoft\CreatorTemp\Rtmpi61v46\downloaded_packages

Installing 1 package: rjson

Installing package into C:/Users/prons/Documents/R/win-library/3.3

(as lib is unspecified)

URL 'https://cloud.r-project.org/bin/windows/contrib/3.3/rjson_0.2.15.zip' 시도합니다

Content type 'application/zip' length 561644 bytes (548 KB)

downloaded 548 KB

 

package rjson successfully unpacked and MD5 sums checked

경고: cannot remove prior installation of package rjson

 

The downloaded binary packages are in

        C:\Users\Public\Documents\ESTsoft\CreatorTemp\Rtmpi61v46\downloaded_packages

"C:/PROGRA~1/R/R-33~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD  \

  INSTALL  \

  "C:/Users/Public/Documents/ESTsoft/CreatorTemp/Rtmpi61v46/devtools2a4047d45b63/geoffjentry-twitteR-815fecc"  \

  --library="C:/Users/prons/Documents/R/win-library/3.3" --install-tests

 

ERROR: dependencies 'bit64', 'rjson' are not available for package 'twitteR'

* removing 'C:/Users/prons/Documents/R/win-library/3.3/twitteR'

에러: Command failed (1)

추가정보: 경고메시지():

Username parameter is deprecated. Please use geoffjentry/twitteR

 

 

Twitter (트위터) API 키 발급받기

http://codedragon.tistory.com/5013

 


Twitter (트위터) 에 접속 

> api_key <- "발급받은 API Key"

> api_secret <- "발급받은 SECRET KEY"

> access_token <- "발급받은 TOKEN"

> access_token_secret <- "발급받은 TOKEN SECRET"

> setup_twitter_oauth(api_key,api_secret, access_token, access_token_secret)

[1] "Using direct authentication"

 

 

> hilton.tweets <- searchTwitter("@hilton", n=1500)

경고메시지():

In doRppAPICall("search/tweets", n, params = params, retryOnRateLimit = retryOnRateLimit,  :

  1500 tweets were requested but the API can only return 90

화살표 오른쪽의 함수를 실행해서 얻은 결과를 맨 왼쪽의 변수(hilton.tweets)에 저장합니다.

, hilton.tweets에는 @hilton을 언급한 내용을 최대 1500개의 message를 가져와서 저장하는 것입니다. 그러나 실제로는 대부분 1500개를 가져오지 못하고 90개만 가져옵니다. 이는 일정시간 동안의 사용량을 접속한 계정인 IP address등으로 파악하여 자동적으로 제한하기 때문입니다.

 


반응형