Created
January 8, 2015 19:34
-
-
Save timelyportfolio/faa39b7a1741006c6e44 to your computer and use it in GitHub Desktop.
use twitter text javascript in R with V8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# devtools::install_github("jeroenooms/curl") | |
# devtools::install_github("jeroenooms/V8") | |
library(V8) | |
ct = new_context() | |
# get source and remove anonymous function wrapper | |
t = readLines( | |
"https://raw.githubusercontent.com/twitter/twitter-text/master/js/twitter-text.js" | |
)[-1] | |
t = t[-length(t)] | |
# save it local | |
# make sure to change file name to desired spot | |
cat( paste0(t,collapse="\n"), file = "c:/twitter.js") | |
# make sure to change file name to desired spot | |
ct$source( "c:/twitter.js" ) | |
#see if it is there | |
ct$eval("twttr.txt") | |
# check for functions and keys within twttr.txt | |
ct$eval( | |
'Object.keys(twttr.txt)' | |
) | |
ct$eval( | |
'twttr.txt.extractMentions("Mentioning @twitter and @jack")' | |
) | |
ct$eval( | |
'twttr.txt.autoLink("link @user, please #request")' | |
) | |
ct$eval( | |
'twttr.txt.autoLink("link @user, and expand url... http://t.co/0JG5Mcq", { | |
urlEntities: [ | |
{ | |
"url": "http://t.co/0JG5Mcq", | |
"display_url": "blog.twitter.com/2011/05/twitte…", | |
"expanded_url": "http://blog.twitter.com/2011/05/twitter-for-mac-update.html", | |
"indices": [ 30, 48 ] | |
} | |
] | |
})' | |
) | |
ct$eval( | |
'var tweet = "This is a test tweet" | |
var remainingCharacters = 140 - twttr.txt.getTweetLength(tweet) | |
remainingCharacters' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment