Rstudio to click a handshake giving an error: unauthorized via twitterR

I am trying to authenticate Rstudio for Twittter using twitteR.

After a handshake, only an error occurs.

My code is:

#install(rcurl, ROAuth, twitteR)
#load(rcurl, ROAuth, twitteR)
reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
consumerKey <- "key"
consumerSecret <- "secret key"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
                             consumerSecret=consumerSecret,
                             requestURL=reqURL,
                             accessURL=accessURL,
                             authURL=authURL)

options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package =  "RCurl")))
twitCred$handshake()

I get a handshake, and he sends me to the login page for Twitter. I authorize and get a pin.

I injected the output into this code:

registerTwitterOAuth(pin number here)

Then I return using "Error: Unauthorized."

I added a new Twitter application account and got a different set of client keys, but still got the same.

+4
source share
3 answers

You can follow the next step:

reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
consumerKey <- "Mjn6tdsadsadkasdklad2SV1l"
consumerSecret <- "58Z7Eldsdfaslkf;asldsaoeorjkfksaVCQtvri"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
                             consumerSecret=consumerSecret,
                             requestURL=reqURL,
                             accessURL=accessURL,
                             authURL=authURL)
twitCred$handshake()

After running this code, you will see the following in the R console message:

To enable the connection, please direct your web browser to: 
https://api.twitter.com/oauth/authorize?oauth_token=scmVODruosvz6Tdsdadadasdsa
When complete, record the PIN given to you and provide it here:

, , PIN-, PIN- R.

registerTwitterOAuth(twitCred)

R TRUE, .

user <- getUser("xxx")
userTimeline(user, n=20, maxID=NULL, sinceID=NULL, includeRts=FALSE)

,

sessionInfo()
update.packages()

twitteR: 1.1.7 = > http://cran.r-project.org/web/packages/twitteR/index.html

+2

, , !!!! Windows 7, 64 RStudio

, - ROAuth, twitteR, RCurl; , CRAN, ,

SSL- , ; , , " ", cacert.pem. , Twitter , ,

Twitter

    library(twitteR)
    library(ROAuth)
    library(RCurl) 

SSL-

   options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))

   download.file(url="http://curl.haxx.se/ca/cacert.pem", destfile="cacert.pem")

, URL- https, http, -

    reqURL <- "https://api.twitter.com/oauth/request_token"
    accessURL <- "https://api.twitter.com/oauth/access_token"
    authURL <- "https://api.twitter.com/oauth/authorize"


    consumerKey <- "====="

    consumerSecret <- "====="


    twitCred <- OAuthFactory$new(consumerKey=consumerKey,
                                 consumerSecret=consumerSecret,
                                 requestURL=reqURL,
                                 accessURL=accessURL,
                                 authURL=authURL)

    #twitCred <- getTwitterOAuth(consumer_key= consumerKey, consumer_secret=consumerSecret)


    twitCred$handshake()

URL- , Twitter - PIN- R

 registerTwitterOAuth(twitCred)

TESTTHE CODE:

testSearch = searchTwitter("#food", n = 10, cainfo="cacert.pem")
Moditweets <- searchTwitter("#Narendra Modi", n = 100)
+1

, 8, , cmd, Rstudio IDE, R

#Open admin shell: In the Start Search box, type cmd, and then press CTRL+SHIFT+ENTER.
#Goto C:/...R../bin/x64, run ./r.exe

install.packages("twitteR") #Takes some time for mirrors to pop-up
library(twitteR)
library(ROAuth)
library(RCurl)
download.file(url="http://curl.haxx.se/ca/cacert.pem",destfile="cacert.pem")
requestURL <- ...
accessURL <- ...
authURL <- ...
consumerKey <- ...
consumerSecret <- ...
twitCred <- OAuthFactory$new(consumerKey=consumerKey, consumerSecret=consumerSecret,
                             requestURL=requestURL, accessURL=accessURL, authURL=authURL)
twitCred$handshake(cainfo="cacert.pem")
registerTwitterOAuth(twitCred)
save(list="twitCred", file="twitteR_credentials")
## Now to get some tweets, place the files cacert.perm and 

twitteR_credentials from bin folder to the the current working directory of Rstudio
library (twitteR)
load("twitteR_credentials")
registerTwitterOAuth(twitCred)
searchTwitter('#Obama', cainfo="cacert.pem", n=5, locale = 'en')
0

Source: https://habr.com/ru/post/1527235/


All Articles