twitteR
twitteR copied to clipboard
Application-Only Authentification - pls help me contribute
Dear TwitteR community,
I would like to contribute my little endeavour to the project, yet I am unable to because I am quite a freshman to programming in general and R especially.
I have figured out how to connect to twitter using Application-Only in R, following those Twitter Instructions:
# my credentials
consumer_key <- "foo"
consumer_secret <- "bar"
# encode your consumer_key and consumer_secret
myAuthorization <- paste0("Basic ",
base64Encode(paste0(consumer_key, ":", consumer_secret)))
# Receiving Bearer access_token
r <- POST(url="https://api.twitter.com/oauth2/token",
add_headers(Authorization=myAuthorization,
"Content-Type"="application/x-www-form-urlencoded;charset=UTF-8"),
body="grant_type=client_credentials")
# ... the server's answer
bearer <- (content(r))$access_token
# the new „searchTwitter“ in its raw form
s <- GET(url="https://api.twitter.com/1.1/search/tweets.json?q=baz",
add_headers(Authorization=paste0("Bearer ", bearer)))
The point in using Application-Only for me and hopefully many others is obvious: E.g. one's rate-limit for searches increases to 450 from 180.
Now I assume I should add my code to the file comm.R and modify the function doAPICall. Apart from that I should think of a way to handle the creation and saving of the bearer-token, which lasts according to twitter kind of forever.
I roughly know how to use git and github, yet I am asking for someone giving me a little advice how to do it right. Some sort of "Fellow, do this. Now do that. There you've sucked, do again, but this time ..." - one might call it mentorship.
Otherwise if someone wants to implement the idea above himself - here you go.
Looking forward to your replies! Best Regards from Munich, Dennis
P.S.: Improvement in my code: Adding the „User-Agent“, i.e. Application Name, however according to the developer website this is nice to have, not need to.
@MemoWalk I have a package that has saved the application token for re-use. You can see my post on creating it here, and the package itself on Github. You will notice that the actual data/oauth_data.RData file is not part of the git repo. This never gets committed, because then others would be using my twitter app.
@rmflight Thank you, for your hints. Although I am not sure, we are exactly talking about the same things - I am specifically adressing Application-Only Authentification which does not need tokens or token_secret.
Yet if I assume you understood me well and I am a little slow in getting your point - do you mean it would suffice to simply save the bearer token to a file alike "bearer.Rdata" and then let it be loaded from the searchTwitter / api functions? (of course this file should never be committed)
If you meant the latter - thank you. First bit to completeness : )