Twitter Api按标签搜索

时间:2018-05-03 04:43:43

标签: javascript twitter

我在世界上如何使用Twitter API?在线的一切似乎已经过时,并且不起作用。我在开发人员门户网站上创建了一个twitter应用程序并获得了访问令牌等。我现在该怎么办?我试图使用JQuery来制作ajax get请求。但我该怎么办?他们的文件完全是垃圾。

3 个答案:

答案 0 :(得分:1)

请参阅the documentation

它表明你可以使用网址

https://api.twitter.com/1.1/search/tweets.json?q=%23superbowl&result_type=recent

使用superbowl主题标签获取最近的推文。

请注意,该网址中的#已编码为%23。您可以找到这些编码的参考here

从文档中,您可以执行以下不同的搜索操作:

Operator                            Finds Tweets...
watching now                        containing both “watching” and “now”. This is the default operator.
“happy hour”                        containing the exact phrase “happy hour”.
love OR hate                        containing either “love” or “hate” (or both).
beer -root                          containing “beer” but not “root”.
#haiku                              containing the hashtag “haiku”.
from:interior                       sent from Twitter account “interior”.
list:NASA/astronauts-in-space-now   sent from a Twitter account in the NASA list astronauts-in-space-now
to:NASA                             a Tweet authored in reply to Twitter account “NASA”.
@NASA                               mentioning Twitter account “NASA”.
politics filter:safe                containing “politics” with Tweets marked as potentially sensitive removed.
puppy filter:media                  containing “puppy” and an image or video.
puppy -filter:retweets              containing “puppy”, filtering out retweets
puppy filter:native_video           containing “puppy” and an uploaded video, Amplify video, Periscope, or Vine.
puppy filter:periscope              containing “puppy” and a Periscope video URL.
puppy filter:vine                   containing “puppy” and a Vine.
puppy filter:images                 containing “puppy” and links identified as photos, including third parties such as Instagram.
puppy filter:twimg                  containing “puppy” and a pic.twitter.com link representing one or more photos.
hilarious filter:links              containing “hilarious” and linking to URL.
puppy url:amazon                    containing “puppy” and a URL with the word “amazon” anywhere within it.
superhero since:2015-12-21          containing “superhero” and sent since date “2015-12-21” (year-month-day).
puppy until:2015-12-21              containing “puppy” and sent before the date “2015-12-21”.
movie -scary :)                     containing “movie”, but not “scary”, and with a positive attitude.
flight :(                           containing “flight” and with a negative attitude.
traffic ?                           containing “traffic” and asking a question.

答案 1 :(得分:1)

由于新的Twitter API需要对所有调用进行身份验证,即使不是特定于给定帐户的调用也是如此,因此很难直接从Javascript对该API进行调用。

但是,您可以使用TweetJS.com,它在Twitter API上提供了Java封装,不需要身份验证。主题标签搜索如下:

TweetJs.Search("#Music",
function (data) {
    console.log(data);
});

答案 2 :(得分:0)

我在github上发布了一个非常简单的示例,该示例应显示如何与twitters api交互。这使用了Twitter api,文档位于https://www.npmjs.com/package/twitter

我的项目使用NodeJS和express进行API调用,并使用dotenv访问配置文件中的隐藏键变量。这是下面的仓库。 https://github.com/scottmilla/Node-Twitter-Starter