简体   繁体   English

Twitter 时间线 - 如何包含转推?

[英]Twitter timeline - How to include retweets?

This loads up a Twitter feed and displays the last tweet.这会加载 Twitter 提要并显示最后一条推文。

Is there a way to include and retrieve all the retweets in this function?有没有办法在这个 function 中包含和检索所有转推?

$(document).ready(function() {
    var url = "http://twitter.com/status/user_timeline/mytwittername.json?count=3&callback=?";
    var lastClass = "";
    $.getJSON(url,
        function(data){
            $.each(data, function(i, item) {
            // check for last tweet
            if (i == (data.length - 1)) {
                lastClass = "class='last'"
            }
            $("#twitter-content ul").append("<li " + lastClass + ">" + item.text.linkify().atify() + " <span class='created_at'>[" + relative_time(item.created_at) + " via " + item.source + "]</span></li>");
        });
    });

    $("#sidebar ul li:last-child").addClass("last");
});

Modify the url variable in your code to be the following:修改代码中的url变量如下:

http://api.twitter.com/1/statuses/user_timeline/mytwittername.json?count=3&include_rts=1&callback=?

The magic is in the include_rts=1 parameter which will cause retweets by the target user to be included in their timeline.神奇之处在于include_rts=1参数,它将导致目标用户的转发包含在他们的时间线中。

The statuses/user_timeline method does not require authentication, however if you do auth, you'll get an extra 200 API calls per hour. statuses/user_timeline方法不需要身份验证,但是如果您进行身份验证,您将每小时额外获得 200 个 API 调用。 Note that the twitter.com REST methods are no longer supported, so be sure to use the versioned API methods when interacting with Twitter. Note that the twitter.com REST methods are no longer supported, so be sure to use the versioned API methods when interacting with Twitter.

Take a look here:看看这里:

https://dev.twitter.com/docs/api/1/get/statuses/retweets/:id https://dev.twitter.com/docs/api/1/get/statuses/retweets/:id

In your loop if you had the id of the original tweet then you could probably get the retweet as well.在您的循环中,如果您有原始推文的 id,那么您可能也可以获得转发。

I haven't tried it, but this is what I found.我没有尝试过,但这是我发现的。

Good Luck!祝你好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM