Avoid The PIN step in ROAuth handshake if I'm the only user?

北城余情 提交于 2019-12-06 04:27:57

问题


Question: Is there a way to avoid having to manually enter a PIN when doing an OAuth handshake?

Context: When making a ROAuth handshake, I am asked to enter a PIN which I obtain by following a link:

rm(list=ls())
library("twitteR")
library("ROAuth")

Credentials <- OAuthFactory$new(
  consumerKey = "...",
  consumerSecret = "...",
  oauthKey = "...",
  oauthSecret = "...",
  requestURL = "https://api.twitter.com/oauth/request_token",
  authURL = "https://api.twitter.com/oauth/authorize",
  accessURL = "https://api.twitter.com/oauth/access_token")

Credentials$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))

Which outputs:

Credentials$handshake(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")) To enable the connection, please direct your web browser to: https://api.twitter.com/oauth/authorize?oauth_token=... When complete, record the PIN given to you and provide it here:

And I enter a PIN.

I would like to avoid this step because everytime I run the script in a new R session I have to manually open the browser to retrieve the PIN. I am the only person using this script.


回答1:


After you perform the handshake you can save the object to a file ...

save(Credentials, file="credentials.RData")

At a later date you can use load() to pull the file in and use your original Credentials object.



来源:https://stackoverflow.com/questions/13746410/avoid-the-pin-step-in-roauth-handshake-if-im-the-only-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!