javascript 通过 twitter api 1.1,通过客户端代码 (js) 获取公共推文

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13056432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 17:44:08  来源:igfitidea点击:

fetch public tweets via twitter api 1.1, via client side code (js)

javascriptjquerytwitterjsonp

提问by

I'm working on a basic personal homepage, consists of a single html document, a .css and jquery*.js file. I want to create a blog-ish look via fetching page content from tweets. The standart widget doesn't fit to the look of the page.

我正在开发一个基本的个人主页,它由一个 html 文档、一个 .css 和 jquery*.js 文件组成。我想通过从推文中获取页面内容来创建博客风格的外观。标准小部件不适合页面的外观。

I can fetch public tweets from any account with no authentication crap (it's crap because it public data anyway) via API v1. But with API v1.1, it returns authentication error. It wants me to authenticate to fetch public data. Try to navigate thisurl. it shows ({"errors":[{"message":"Bad Authentication data","code":215}]});.

我可以通过 API v1.0 从任何没有身份验证废话的帐户获取公共推文(这是废话,因为它无论如何都是公共数据)。但是对于 API v1.1,它返回身份验证错误。它要我进行身份验证以获取公共数据。尝试导航 网址。它显示({"errors":[{"message":"Bad Authentication data","code":215}]});

My question is is there a way to fetch public tweets via client side js? I don't want to create an app to just fetch public data. I don't wan't to use identi.ca or else, but Twitter pushes me to do.

我的问题是有没有办法通过客户端 js 获取公共推文?我不想创建一个应用程序来获取公共数据。我不想使用 identi.ca 或其他,但 Twitter 逼我这样做。



Upon the comment of Zachary Kinebel to Norguard's answer, I thought, as a comment of Norguard's might be helpful to others, I should put it here:

根据 Zachary Kinebel 对 Norguard 的回答的评论,我想,由于 Norguard 的评论可能对其他人有帮助,我应该把它放在这里:



/search.json?q=from:nerdswguitars=== recent tweets by NerdsWGuitars /search.json?q=to:nerdswguitars=== recent tweets to NerdsWGuitars /search.json?q=from:nerdswguitarsOR to:nerdswguitars=== both. /search.json?q=@nerdswguitars=== posts involving NerdsWGuitars. /search.json?q=#nerdswithguitars=== posts trending "nerdswithguitars". But you MUST make sure that you're properly URL encoding the query. Read more here: https://dev.twitter.com/docs/using-searchand if you can't find what it is that you're looking for, out of this, then you need to be a lot more specific

/search.json?q=from:nerdswguitars=== NerdsWGuitars/search.json?q=to:nerdswguitars最近的推文 === 最近发给 NerdsWGuitars 的推文/search.json?q=from:nerdswguitarsto:nerdswguitars=== 两者。/search.json?q=@nerdswguitars=== 涉及 NerdsWGuitars 的帖子。/search.json?q=#nerdswithguitars=== 发布趋势“nerdswithguitars”。但是您必须确保您正确地对查询进行了 URL 编码。在这里阅读更多信息:https: //dev.twitter.com/docs/using-search如果你找不到你正在寻找的东西,那么你需要更加具体

采纳答案by Norguard

EDIT

编辑

In the wonderful world of bad ideas, Twitter is sunsetting this answer, as of May 2013, and will require, at minimum, that you either use one of their widgets, and shoehorn it in, or that you set up an application and do application-level authentication, even for public-timeline GETrequests.

在这个充满糟糕想法的美妙世界中,Twitter 将在 2013 年 5 月取消这个答案,并且至少需要您使用他们的一个小部件并将其硬塞进去,或者您设置一个应用程序并执行应用程序- 级别的身份验证,即使对于公共时间线GET请求也是如此。

If they change their mind, or delay the throwing of the switch, this will at least continue to be here.

如果他们改变主意,或者推迟投掷开关,这至少会继续存在。



Use the Search API:

使用搜索 API:

"http://search.twitter.com/search.json?q=nerdswguitars"

You can use the URL-encoded #or @in front of search terms. You can also use keywords like fromor to, and specify limits, et cetera.

您可以使用 URL 编码#@前面的搜索词。您还可以使用像fromor 之类的关键字to,并指定限制等。

回答by ezzatron

You can use Mooch, a small application designed to solve this exact problem. Setting up a new Moochservice is very simple, and utilizes Heroku. The deployment process requires the Heroku Toolbeltapplication.

您可以使用Mooch,这是一个旨在解决这个确切问题的小型应用程序。设置新的Mooch服务非常简单,并且使用Heroku。部署过程需要Heroku Toolbelt应用程序。

Step 1: Create a Twitter app

第 1 步:创建一个 Twitter 应用程序

Step 2: Get Mooch

第 2 步:获取Mooch

  • Clone the Git repository (git clone [email protected]:eloquent/mooch.git).
  • Change into the Moochroot directory.
  • 克隆 Git 存储库 ( git clone [email protected]:eloquent/mooch.git)。
  • 切换到Mooch根目录。

Step 3: Create a Heroku app

第 3 步:创建 Heroku 应用程序

  • Sign in with Heroku Toolbelt(heroku login).
  • Create a new app with heroku create.

Step 4: Configuration

第 4 步:配置

Moochauthenticates requests to the Twitter API using the application-only authenticationmethod. This requires the consumer key and secret from the Twitter application created in step 1.

Mooch使用仅限应用程序的身份验证方法对对 Twitter API 的请求进行身份验证。这需要来自第 1 步中创建的 Twitter 应用程序的使用者密钥和机密。

Example authentication configuration

示例身份验证配置

heroku config:set MOOCH_CONSUMER_KEY=xvz1evFS4wEEPTGEFPHBog
heroku config:set MOOCH_CONSUMER_SECRET=L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg

Step 5: Deploy

第 5 步:部署

  • git push heroku master
  • git push heroku master

The new Moochservice should now be ready for use. Check the Heroku dashboardfor the service's location.

新的Mooch服务现在应该可以使用了。检查Heroku 仪表板以获取服务的位置。

For more detailed configuration instructions, a demo application and more, check out the Mooch READMEon GitHub.

有关更详细的配置说明、演示应用程序等,请查看GitHub 上的Mooch README