0

I know literally zero about the R programming language and have come to an impasse where I am truly and utterly stuck.

I've borrowed lots of other peoples code and have been busy debugging placing in additional libraries that are not contained within the help text of the packages to get to a point I feel is tantalisingly close.

That said I simply cannot get R to correctly authorise a twitter search or OAuth Connection.

I run my code, it throws up the following error screen.

Error On Authorisation

Alongside that in the R-Compiler the error message of twitCred$handshake() To enable the connection, please direct your web browser to: http://api.twitter.com/oauth/authorize?oauth_token=r4VjQQAAAAAA4-K7AAABYlMXEws When complete, record the PIN given to you and provide it here: registerTwitterOAuth(twitCred) Error: Forbidden

I read that there can be issues with the call back if the weblinks within the code do not read https:// and are left with http:// so that has been amended accordingly to no avail.

My twitter settings are as follows

Twitter Settings

I followed the advice laid down in this thread but it didn't seem to help or I did something I wasn't supposed to.... StackOverflow Support Article

So here is my code please shout if you can see the obvious to you not to me error or can offer some advice.

    ## install devtools package if it's not already
if (!requireNamespace("devtools", quietly = TRUE)) {
  install.packages("devtools")
}

## install dev version of rtweet from github
devtools::install_github("mkearney/rtweet")

## load rtweet package
library(rtweet)

install.packages("rtweet")
install.packages("RCurl")
install.packages("tm")
install.packages("wordcloud")
install.packages("httpuv")
install.packages(c('ROAuth','RCurl'))
install.packages("rjson")
install.packages("bit64")
install.packages("httr")

require(twitteR)
require(RCurl)
require(tm)
require(wordcloud)
require(httpuv)
require(rtweet)
require(ROAuth)
require(RCurl)
require(rjson)
require(bit64)
require(httr)





## CURL LOGIC ## 


reqURL <- "https://api.twitter.com/oauth/request_token"
accessURL <- "https://api.twitter.com/oauth/access_token"
authURL <- "https://api.twitter.com/oauth/authorize"
api_key <- "AAAAAAA"
consumer_key <- "AAAAAAA"
consumerKey <- "AAAAAAA"
consumerSecret <- "AAAAAAA"
twitCred <- OAuthFactory$new(consumerKey=consumerKey,
access_token <- "AAAAAAA"
access_token_secret <- "AAAAAAAAAA"
consumerSecret=consumerSecret,
requestURL=reqURL,
accessURL=accessURL,
authURL=authURL)
twitCred$handshake()
registerTwitterOAuth(twitCred)


##################

The duplications of API keys are meant to be there as I have tried so many connection advice threads and am lost now on the hows whys and wherefores...

Mr Deans
  • 269
  • 1
  • 4
  • 21

1 Answers1

0

You can use the twitteR package for data mining Twitter. Please find the below code for your reference.

install.packages('twitteR')
install.packages('ROAuth')    
install.packages("RCurl")

library(twitteR)    
require("ROAuth")    
require("RCurl")

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


t_consumer_key<-    'YOUR CONSUMER KEY'
t_consumer_secret<- 'YOUR CONSUMER SECRET KEY'
t_access_token<-    'YOUR ACCESS TOKEN'
t_access_secret <-  'YOUR ACCESS SECRET'


setup_twitter_oauth(t_consumer_key,t_consumer_secret,t_access_token,t_access_secret)

list <- searchTwitter("iphone")

If you click on the link in below image you will get all the API keys