-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoauth.R
23 lines (19 loc) · 881 Bytes
/
oauth.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Create an app on twitter and they will provide you client id and
# client secret and you can use it to get the access token.
# package required : httr
tweetOauth <- function(client_id = NULL, client_secret = NULL) {
if (is.null(client_id) || is.null(client_secret)) {
stop("Nither client_id nor client_secret can be NULL")
}
request <- "https://api.twitter.com/oauth/request_token"
authorize <- "https://api.twitter.com/oauth/authenticate"
access <- "https://api.twitter.com/oauth/access_token"
twitter <- httr::oauth_endpoint(request,authorize,access)
myapp <- httr::oauth_app("twitter", key = client_id, secret = client_secret)
result <- try(token <- httr::oauth1.0_token(twitter, myapp))
result <- class(result)
if( result[1] == "try-error") {
stop("Either internet connection is off or your argument(s) are incorrect")
}
token
}