【问题标题】:Twitter Api Searching by Hashtag按标签搜索 Twitter Api
【发布时间】:2018-10-13 07:10:59
【问题描述】:

我到底如何使用 Twitter API?网上的一切似乎都过时了,而且不起作用。我在开发者门户上创建了一个 twitter 应用程序并获得了我的访问令牌等。我现在该怎么办?我正在尝试使用 JQuery 发出 ajax 获取请求。但是我该怎么做?他们的文档完全是垃圾。

【问题讨论】:

    标签: javascript twitter


    【解决方案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.
    

    【讨论】:

    • 这给了我{"errors":[{"code":215,"message":"Bad Authentication data."}]}
    • @user12888 请发布您正在使用的代码,因为该错误表明您没有正确进行身份验证,因此如果不查看您的代码就很难判断出了什么问题
    • 我没有验证任何东西。我该怎么做?
    • @user12888 您使用从 twitter 获得的访问令牌并将它们添加到请求中 - 以查看 stackoverflow.com/questions/17067996/… 为例
    • 如果我使用%23,它会给我{"errors":[{"code":32,"message":"Could not authenticate you."}]}。否则正常搜索工作。我正在使用 Postman 发送此请求。
    【解决方案2】:

    由于新的 Twitter API 需要对所有调用进行身份验证,即使是那些不特定于给定帐户的调用,直接从 Javascript 调用 API 变得非常困难。

    但是,您可以使用TweetJS.com,它在 Twitter API 上提供了一个 Javascript 包装器,不需要身份验证。主题标签搜索如下所示;

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 2014-05-24
        • 2013-06-10
        • 2013-08-15
        • 2020-11-17
        • 1970-01-01
        • 1970-01-01
        • 2015-12-10
        • 2011-07-14
        • 2014-01-12
        相关资源
        最近更新 更多