smappR icon indicating copy to clipboard operation
smappR copied to clipboard

Authorization problem

Open nurandi opened this issue 9 years ago • 0 comments

I encounter an error when run getTimelines():

Error: Authorization Required 

Then, I wrote this script to verify that all credentials within oauth folder are valid

status <- NULL
for (cr in list.files("oauth", full.names=T)){
  load(cr)
  consumerKey <- my_oauth$consumerKey
  consumerSecret <- my_oauth$consumerSecret
  accessToken <- my_oauth$oauthKey
  accessTokenSecret <- my_oauth$oauthSecret

  app <- oauth_app("twitter",
                   key = consumerKey,
                   secret = consumerSecret)

  twitter_token <- Token1.0$new(endpoint = NULL, 
                                params = list(as_header = TRUE), 
                                app = app, 
                                credentials = list(oauth_token = accessToken,
                                                   oauth_token_secret = accessTokenSecret))

  req <- GET("https://api.twitter.com/1.1/account/verify_credentials.json",
             config(token = twitter_token))
  stop_for_status(req)

  status <- c(status, req$status_code)
}

All return status code 200, which means all is OK (ref)

So, do you have idea what my problem actually is?


UPDATE

I modified getLimitTimeline () function be:

getLimitTimeline <- function(my_oauth){
  options("httr_oauth_cache"=FALSE)
  app <- httr::oauth_app("twitter", key = my_oauth$consumerKey, 
                         secret = my_oauth$consumerSecret)
  credentials <- list(oauth_token = my_oauth$oauthKey, oauth_token_secret = my_oauth$oauthSecret)
  twitter_token <- httr::Token1.0$new(endpoint = NULL, params = list(as_header = TRUE), 
                                      app = app, credentials = credentials)

  url <- "https://api.twitter.com/1.1/application/rate_limit_status.json"
  response <- httr::GET(url, httr::config(token = twitter_token))
  if (response$status_code == 200) {
    return(as.numeric(response[[3]]$`x-rate-limit-remaining`))
  } else {
    return(0)
  }

}

It works without error

nurandi avatar Feb 12 '16 10:02 nurandi