POST 使用 Oauth 和 HTTR,R 更新到 Twitter

POST update to Twitter using Oauth and HTTR, R

我正在尝试 post 使用 api 更新 Twitter。按照 https://github.com/hadley/httr/blob/master/demo/oauth1-twitter.r 中的步骤,我可以让 GET 调用工作,但我还没有设法让 POST 工作。相关代码如下:

library(httr)
library(httpuv)


oauth_endpoints("twitter")

myapp <- oauth_app("twitter", 
key = "key"
secret = "secret" 
) 

twitter_token <- oauth1.0_token(oauth_endpoints("twitter"), myapp)


#this works fine
req <- GET("https://api.twitter.com/1.1/statuses/home_timeline.json", 
config(token = twitter_token)) 



#this doesn't work.  Returns error 403: status is forbidden
POST(url = "https://api.twitter.com/1.1/statuses/update.json",
     body = "test", 
     config(token = twitter_token)
     )

任何允许从 R 更新状态(推文)的解决方案都是可以接受的。

The docs 说你需要传递一个参数 status 作为查询参数,而不是在正文中,这是有道理的 b/c 无论如何它只能是 140 个字符。

POST("https://api.twitter.com/1.1/statuses/update.json",
     query = list(status = "testing from R"),
     config(token = twitter_token)
)