在Twitter Feed中过滤@replies? [英] Filter out @replies in a Twitter feed?
问题描述
我在我的网站顶部有一个Twitter个人资料供稿,但我想知道是否有办法过滤出我的@replies并只显示我的状态更新?
感谢
如果您使用Blogger和类似网站的标准Twitter供稿网页代码,做的伎俩。它位于Twitter供稿和回调之间,并将回复从服务器响应中删除。
对于博客徽章,标准Twitter网页代码以两个< script>
标签结尾。第一个提供显示你的推文的功能。第二个查询推文以显示推文。
在twitter查询之前将此脚本添加到您的徽章代码中。它提供了一个名为filterCallback的新函数,它从Twitter响应中删除@replies。
< script type =text / javascript>
函数filterCallback(twitter_json){
var result = [];
for(var index in twitter_json){
if(twitter_json [index] .in_reply_to_user_id == null){
result [result.length] = twitter_json [index];
}
if(result.length == 5)break; //编辑这个来改变显示的最大推文
twitterCallback2(result); //将推文传递到原始回调。不要改变!
}
< / script>
twitter查询本身有一个参数,它指定响应返回时要调用的函数。在博客的情况下,该函数被称为'twitterCallback2' - 你可以在网页代码中搜索它(查找 callback = twitterCallback2
)。要使用新过滤器,您需要使用 filterCallback
替换文本 twittercallback2
。过滤器被硬编码,然后在完成时调用 twitterCallback2
。
以下是我的博客文章:用Twitter Feed过滤回复
I have a feed from my Twitter profile on the top of my site but I wondered if there is a way to filter out my @replies and only show my status updates?
Thanks
If you're using the standard Twitter feed web code for Blogger and similar sites, this bit of Javascript does the trick. It sits between the Twitter feed and the callback and strips replies out of the server response.
For a blog badge, the standard Twitter web code ends with two <script>
tags. The first provides the function that displays your tweets. The second queries twitter for the tweets to display.
Add this script to your badge code before the twitter query. It provides a new function called filterCallback which strips @replies from the Twitter response.
<script type="text/javascript">
function filterCallback( twitter_json ) {
var result = [];
for(var index in twitter_json) {
if(twitter_json[index].in_reply_to_user_id == null) {
result[result.length] = twitter_json[index];
}
if( result.length==5 ) break; // Edit this to change the maximum tweets shown
}
twitterCallback2(result); // Pass tweets onto the original callback. Don't change it!
}
</script>
The twitter query itself has a parameter which specifies what function to call when the response comes back. In blogger's case, that function is called 'twitterCallback2' - you can search for it in the web code (look for callback=twitterCallback2
). To use the new filter you need to replace the text twittercallback2
with filterCallback
. The filter is hard coded to then call twitterCallback2
when it's done.
Note that as this will reduce the number of displayed tweets if some of the repsonses from Twitter are replies, so you have to increase the count parameter in the call to allow for that. The new function then limits the number of displayed replies to five - edit the code to change that.
Here's my blog post about it: Filter Replies out of Twitter Feed
这篇关于在Twitter Feed中过滤@replies?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!