【问题标题】:Trouble receiving data from Twitter in R在 R 中从 Twitter 接收数据时遇到问题
【发布时间】:2018-09-10 17:00:06
【问题描述】:

我想从推文中获取数据。
但这些都是错误。
请帮我获取数据?

按代码

install.packages("rtweet")
library(rtweet)
# plotting and pipes - tidyverse!
library(ggplot2)
library(dplyr)
# text mining library
library(tidytext)
# whatever name you assigned to your created app
appname <- "**********"
## api key (example below is not a real key)
key <- "**************"
## api secret (example below is not a real key)
secret <- "***********"
twitter_token <- create_token(
  app = appname,
  consumer_key = key,
  consumer_secret = secret)
rstats_tweets <- search_tweets(q = "#rstats",
                               n = 500)

check_twitter_oauth () 中的错误:OAuth 身份验证错误:
这很可能意味着您错误地调用了 setup_twitter_oauth () '

curl 中的错误 :: curl_fetch_memory (url, handle = handle):
已达到超时:连接在 10,000 毫秒后超时

【问题讨论】:

  • 你在 twitter api 上创建了应用程序了吗?如果你完成了,请再次检查应用名称,consumer_key,和consumer_secret 作为替代,你可以使用类似“twitteR”的包

标签: r authentication twitter oauth


【解决方案1】:

documentation 声称:

API 授权

  • 首次发出 API 请求时(例如 search_tweets()、stream_tweets()、get_followers()),将打开一个浏览器窗口。
  • 登录到您的 Twitter 帐户。
  • 同意/授权 rtweet 应用程序。

就是这样!

但是,这对我不起作用。

我必须按照 rtweet 教程如何obtaining and using access tokens

# install from CRAN
install.packages("rtweet")
# load rtweet
library(rtweet)

我还必须安装httpuv 包。教程中没有提到这一点,但您会在 R 中收到相应的错误消息。

oauth_listener(authorize_url, is_interactive) 中的错误:
捕获 OAuth 凭据所需的 httpuv 包。

install.packages("httpuv")

然后在 apps.twiter.com 上使用正确的回调 URL 创建您的 Twitter 应用:

要创建 Twitter 应用,请导航至 apps.twitter.com,然后通过提供名称创建新应用, 您选择的描述和网站(提供的示例屏幕截图
重要提示在回调 URL 字段中,确保输入以下内容:http://127.0.0.1:1410
如果您同意,请勾选“是”,然后单击“创建您的 Twitter 应用程序”。

## whatever name you assigned to your created app
appname <- "rtweet_token"

## api key (example below is not a real key)
key <- "XYznzPFOFZR2a39FwWKN1Jp41"

## api secret (example below is not a real key)
secret <- "CtkGEWmSevZqJuKl6HHrBxbCybxI1xGLqrD5ynPd9jG0SoHZbD"

## create token named "twitter_token"
twitter_token <- create_token(
  app = appname,
  consumer_key = key,
  consumer_secret = secret)

然后,最后,在执行此代码后会打开一个浏览器窗口(如下所示):

http://localhost:1410/?oauth_token=asdfasdfasdfaf5naw&oauth_verifier=dffasdfsdfsdfsdfsdfsk9jIQxDG6

显示消息:

身份验证完成。请关闭此页面并返回 R。

现在你应该很高兴了。

另见:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-08
    • 2022-12-10
    • 2019-09-12
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 2021-11-17
    相关资源
    最近更新 更多