首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在R中跟踪使用twitter Rest Api的人

在R中跟踪使用twitter Rest Api的人
EN

Stack Overflow用户
提问于 2016-06-01 05:31:28
回答 1查看 775关注 0票数 3

我正在查看来自推特的文档来跟踪某人。我已经授权帐户使用twitteR包和api_keyaccess_token等。由于这是一个POST操作,我决定在R中使用httr包。文档中提供的示例之一是

id=1401881&follow=true

因此,只是将user_id更改为我想要跟踪的帐户。

代码语言:javascript
运行
复制
library(httr)
POST("https://api.twitter.com/1.1/friendships/create.json?user_id=1401881&follow=true",verbose())

其中1401881是我想要遵循的id。

这给了我

代码语言:javascript
运行
复制
-> 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

从响应信息中可以看到,它说的是Bad Request,我相信我生成的URL是错误的。我也试过

代码语言:javascript
运行
复制
POST("https://api.twitter.com/1.1/friendships/create", verbose(), 
    body = list(user_id = "101311381"), encode = "json")

我尝试过各种其他方法,也尝试过谷歌搜索,但无法找到解决方案。任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2016-06-28 06:33:10

尝试将oauth_token (从twitteR包生成)添加到POST请求中

代码语言:javascript
运行
复制
library(httr)
POST("https://api.twitter.com/1.1/friendships/create.json?user_id=1401881&follow=true", 
           config(token = oauth_token))
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37560164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档