Follow someone using Twitter Rest Api in R

I am going through this documentation from twitter to follow someone. I have allowed the account using package twitteRc api_key, access_tokenetc. Since this is an operation POST, I decided to use the package httrin R. One example given in the documentation is

https://api.twitter.com/1.1/friendships/create.json?user_id=1401881&follow=true

That way, just changing user_idto the value of the account I want to follow.

library(httr)
POST("https://api.twitter.com/1.1/friendships/create.json?user_id=1401881&follow=true",verbose())

where 1401881is the identifier I want to execute.

It gives me

-> POST /1.1/friendships/create.json?user_id=1401881&follow=true HTTP/1.1
-> User-Agent: libcurl/7.39.0 r-curl/0.9.1 httr/1.1.0
-> Host: api.twitter.com
-> Accept-Encoding: gzip, deflate
-> Cookie: guest_id=v1%3A146475568975546263
-> Accept: application/json, text/xml, application/xml, */*
-> Content-Length: 0
-> 
<- HTTP/1.1 400 Bad Request
<- content-encoding: gzip
<- content-length: 87
<- content-type: application/json; charset=utf-8
<- date: Wed, 01 Jun 2016 05:15:42 GMT
<- server: tsa_b
<- strict-transport-security: max-age=631138519
<- x-connection-hash: 6abd7db7f4c47058bf9d96e9ae23fb83
<- x-response-time: 5
<- 
Response [https://api.twitter.com/1.1/friendships/create.json? user_id=1401881&follow=true]
Date: 2016-06-01 05:15
Status: 400
Content-Type: application/json; charset=utf-8
Size: 62 B

As seen in the response message, it says Bad Requestfrom which I believe that the URL I created is incorrect. I also tried using

POST("https://api.twitter.com/1.1/friendships/create", verbose(), 
    body = list(user_id = "101311381"), encode = "json")

Google, . .

+4
1

oauth_token ( twitteR) POST

library(httr)
POST("https://api.twitter.com/1.1/friendships/create.json?user_id=1401881&follow=true", 
           config(token = oauth_token))
+2

All Articles