Using R to send tweets

I saw a nice demonstration of tweets from R in a presentation a few months ago. The zero code used by the presenter is here:

http://www.r-bloggers.com/twitter-from-r%E2%80%A6-sure-why-not/

short and sweet code: library ("RCurl") opts <- curlOptions (header = FALSE, userpwd = "username: password", netrc = FALSE)

tweet <- function(status){
  method <- "http://twitter.com/statuses/update.xml?status="
  encoded_status <- URLencode(status)
  request <- paste(method,encoded_status,sep = "")
  postForm(request,.opts = opts)
}

With this function, you can send a tweet simply using the update function:

tweet("This tweet comes from R! #rstats")

I thought this might be a useful way to announce the completion of long work assignments. I tried to run this on my machine and I got some error:

[1] "\n\n \n\n" ( "Content-Type" )                            "application/xml" "utf-8" : postForm (,.opts = opts): ,

, , ? , R -, !!

+3
4
+11

, , twitteR CRAN, .

+9

R Twitter-API - twitteR. Twitter-API-APP : https://apps.twitter.com/

:

consumer_key <- "yourcredentials"
consumer_secret <- "yourcredentials"
access_token <- "yourcredentials"
access_secret <- "yourcredentials"
setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)

( : 2400 ):

tweet("Hello World")
0

twitteR ...

See here for a demonstration of how to do your own Twitter authentication and use the API using the httr package.

-1
source

Source: https://habr.com/ru/post/1776375/


All Articles