【问题标题】:Twitter APIs : update working, but filter does notTwitter API:更新工作,但过滤器没有
【发布时间】:2012-07-07 12:57:46
【问题描述】:

Twitter API:更新工作,但过滤器没有 javascript twitter oauth twitter-api jsoauth

在下面的代码中,我通过 bytespider 从 jsOAuth 库中实例化了一个 OAuth 的实例

    // jsoauth API reference:
    // http://bytespider.github.com/jsOAuth/api-reference/

    var twitter = new OAuth(oauthOptions);

    //authentication occurs

    console.log('url: ' + url);
    console.log('data: ' + JSON.stringify(data));

    twitter.post(
        url,
        data,
        success,
        failure
    );

当我访问流时:

    url: https://stream.twitter.com/1/statuses/filter.json 
    data: {"track":"%40twitterapi"} 
    --> This does not work, neither the `success` nor `failure` callbacks get called, just hangs

当我发推文时:

    url: https://api.twitter.com/1/statuses/update.json 
    data: {"status":"foobar","trim_user":true,"include_entities":true} 
    --> This works, the `success` callback gets called

我的猜测是身份验证详细信息没有通过stream.twitter.com API,即使它通过api.twitter.com API。可以安全地排除 OAuth 问题,因为能够发送推文表明身份验证已成功。

我在这里做错了什么?

谢谢!

【问题讨论】:

    标签: javascript oauth twitter


    【解决方案1】:

    不是这样的

    这不起作用,successfailure 回调都没有 调用,只是挂起

    因为您使用的是Streaming API,它的意思是“挂起”,因为使用这意味着您正在打开与 Twitter 服务器的连接,只要应用程序正在运行,该服务器就会保持活动状态。然后,每条新推文都会像通过管道的水一样实时发送到此连接。

    您应该考虑使用HTML5 WebSockets

    【讨论】:

    • +1 && check @Arvin:从这个意义上说,没想到它是流式传输的,因为它出现在他们的“REST API”部分(dev.twitter.com/docs/api)下。感谢您指出这一点!
    • @Arvin :我在这里提出了一个后续问题:stackoverflow.com/questions/11374771/…‌​-jsoauth 如果您知道如何使用 HTML5 WebSockets 做到这一点,并且想展示如何做到这一点,那就太好了!
    猜你喜欢
    • 2019-07-11
    • 1970-01-01
    • 2020-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多