blogger

I have a little yellow bar at the top of my blog that is supposed to show my latest Tweet. It's a nice unobtrusive way to show that I'm out there and I'm active, and maybe if the tweet is interesting to you, you'll stop by Twitter and follow me.

我的博客顶部有一个黄色的小条,该条应该显示我的最新Tweet。 这是显示我在外面并且很活跃的一种不错的吸引人的方式,如果这条推文对您来说很有趣,那么您将在Twitter停下来关注我。

However, I noticed it stopped working recently. It was blank:

但是,我注意到它最近停止工作。 它是空白的:

Weird. It'd worked great for years, plural. I searched around and found a few posts on GetSatisfaction asking about it, some recent, some not recent at all. Some people are having the code work on some accounts and not others.

奇怪的。 多年以来,它一直运作很好,很复杂。 我四处搜寻,发现有关GetSatisfaction的一些帖子对此进行了询问,有些是最近的,有些则不是最近的。 某些人正在某些帐户而不是其他人使用代码。

Unfortunately, Twitter seems to have quietly deprecated the code I was using. It's still there but there are no pages on Twitter on how to add tweets to your blog in a low-level controlled way.

不幸的是,Twitter似乎已悄然弃用了我正在使用的代码。 它仍然存在,但是Twitter上没有页面介绍如何以低级受控方式向您的博客添加推文。

Twitter wants you to visit http://twitter.com/badges and use their existing Twitter Widgets. These are very typical of other sites, in that they are boxes with your tweets in them.

Twitter希望您访问http://twitter.com/badges并使用其现有的Twitter Widgets 。 这些是其他网站中非常典型的网站,因为它们是其中装有您的推文的盒子。

For example, here's a box of Tweets to the right, however, that's a little garish for my tastes.

例如,这是右边的一盒Tweets,但是,这对于我的口味来说有点扎眼。

Here's the code I was using to show just the very first tweet on the top of page. First at the top of the page I have a div that will hold my most recent tweet.

这是我用来在页面顶部仅显示第一条推文的代码。 首先,在页面顶部,我有一个div,它将保存我的最新推文。

<div id="twitter_div"> <a href="http://twitter.com/shanselman" id="twitter-link" >Latest Tweet:  </a> <span id="twitter_update_list"></span></div>

Then later at the bottom I have these two scripts. These are what appear to be either not supported or not advertised by Twitter anymore.

然后,在底部的后面,我有这两个脚本。 Twitter似乎不再支持或不再宣传这些内容。

<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script><script type="text/javascript" src="http://twitter.com/statuses/user_timeline/shanselman.json?callback=twitterCallback2&count=1"></script>

Now, don't use it just like that if you want to get only 1 original tweet as I do. Because it's this very code that stopped working recently. Except it stopped working sometimes. But did it?

现在,如果您只想像我一样只获得1条原始推文,请不要像那样使用它。 因为正是这样的代码最近才停止工作。 除了有时停止工作。 但是吗?

To figure it out quickly, first I visited this URL in my browser. It returns JSON of all my tweets.

为了快速找出问题,我首先在浏览器中访问了该URL。 它返回我所有推文的JSON。

http://twitter.com/statuses/user_timeline/shanselman.json?count=1

http://twitter.com/statuses/user_timeline/shanselman.json?count=1

However sometimes I get this:

但是有时候我得到这个:

[]

Yes, really. An empty JSON array. But why? Well at this moment in time my "most recent tweet" is actually a native retweet. It's not a tweet from me, it's a retweet of a YouTube video. See below?

对真的。 空的JSON数组。 但为什么? 好吧,在此时此刻,我的“最新推文”实际上是本地推文。 这不是我发的推文,而是YouTube视频的转推。 见下文?

Perhaps this JSON Twitter API was created before the Native Retweet was invented. But, if I tweet something fresh, at hit http://twitter.com/statuses/user_timeline/shanselman.json?count=1 again, I'll see this minimized JSON:

也许此JSON Twitter API是在发明本机转发之前创建的。 但是,如果我发布了一些新鲜的东西,请再次点击http://twitter.com/statuses/user_timeline/shanselman.json?count=1 ,我将看到此最小化的JSON:

[{"in_reply_to_status_id":null,"text":"Testing for a blog post. Move along. This tweet never happened.","created_at":"Thu May 12 23:44:13 +0000 2011","favorited":false,"retweet_count":0,"source":"web","in_reply_to_screen_name":null,"in_reply_to_status_id_str":null,"id_str":"68823826439487488","contributors":null,"retweeted":false,"in_reply_to_user_id_str":null,"place":null,"coordinates":null,"geo":null,"in_reply_to_user_id":null,"truncated":false,"user":{"is_translator":false,"notifications":false,"created_at":"Tue May 01 05:55:26 +0000 2007","profile_sidebar_border_color":"b8aa9c","listed_count":3909,"following":true,"description":"Tech, Diabetes, Parenting, Race, Linguistics, Fashion, Podcasting, Media, Culture, Code, Ratchet.","show_all_inline_media":true,"geo_enabled":true,"profile_use_background_image":true,"profile_image_url":"http:\/\/a1.twimg.com\/profile_images\/1344567304\/image_normal.jpg","contributors_enabled":false,"verified":false,"profile_background_color":"d1cdc1","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/157325454\/twilk_background_4ca8e4832a970.jpg","screen_name":"shanselman","default_profile_image":false,"statuses_count":40900,"id_str":"5676102","default_profile":false,"friends_count":2616,"profile_text_color":"696969","lang":"en","profile_sidebar_fill_color":"b8aa9c","followers_count":36994,"protected":false,"location":"Portland, Oregon","follow_request_sent":false,"profile_background_tile":true,"favourites_count":2089,"name":"Scott Hanselman","url":"http:\/\/hanselman.com","id":5676102,"time_zone":"Pacific Time (US & Canada)","utc_offset":-28800,"profile_link_color":"72412c"},"id":68823826439487488}]

I can run it by the http://jsbeautifier.org and it looks lovely...

我可以在http://jsbeautifier.org上运行它,它看起来很可爱...

[{    "in_reply_to_status_id": null,    "text": "Testing for a blog post. Move along. This tweet never happened.",    "created_at": "Thu May 12 23:44:13 +0000 2011",    "favorited": false,    "retweet_count": 0,    "source": "web",    "in_reply_to_screen_name": null,    "in_reply_to_status_id_str": null,    "id_str": "68823826439487488",    "contributors": null,    "retweeted": false,    "in_reply_to_user_id_str": null,    "place": null,    "coordinates": null,    "geo": null,    "in_reply_to_user_id": null,    "truncated": false,    "user": { ..... SNIP! .....}}]

So, Twitter has a nice JSON API that is old and doesn't support Native Retweets but I want the most recent tweet, my way.

因此,Twitter有一个不错的JSON API,该API很旧且不支持本机转发,但我想以我的方式获取最新的转发。

Bam. http://twitter.com/statuses/user_timeline/shanselman.json?count=5

am http://twitter.com/statuses/user_timeline/shanselman.json?count = 5

Of course, if my last five tweets are all Native Retweets then it all falls part, but you get the idea.

当然,如果我的最后5条推文全部是Native Retweets,那么全部都属于其中,但是您明白了。

If I was really serious, I could even remove @replies, only showing original tweets, remembering that this JSON API doesn't include Native Retweets in its results.

如果我真的很认真,我什至可以删除@replies,只显示原始推文,请记住,此JSON API在其结果中不包括本机推文。

I found some code on BarneyB's blog that is a modification of Twitter's original code. He mentions in the comments that he's removing replies in his code. I just took his code and stop the code as soon as a valid original non-replied tweet is found. In this case, I search the 5 tweets I requested that were returned from Twitter. If it turns out I reply a lot and get an empty payload, maybe I'll increase that number.

我在BarneyB的博客上找到了一些对Twitter原始代码的修改的代码。 他在评论中提到他正在删除代码中的回复。 我只是拿走了他的代码,并在找到有效的原始未回复推文后立即停止了代码。 在这种情况下,我搜索了我要求从Twitter返回的5条推文。 如果事实证明,我回答很多,得到的负载是空的,也许我会增加这个数字。

The conclusion here is that this code still "works," it just doesn't see Native Retweets:

这里的结论是该代码仍然“有效”,只是看不到本机转发:

<div id="twitter_div"> <a href="http://twitter.com/shanselman" id="twitter-link" >Latest Tweet:  </a> <span id="twitter_update_list"></span></div>

Then later...

后来...

<script type="text/javascript" src="http://twitter.com/javascripts/blogger.js"></script><script type="text/javascript" src="http://twitter.com/statuses/user_timeline/shanselman.json?callback=twitterCallback2&count=1"></script>

My issue was that I want a single tweet, specifically the first original, non-native-retweet, non-reply tweet. I solved it by taking BarneyB's @reply-filtering code and adding a check that breaks out of the loop. I ask Twitter for 5 tweets, but as soon as I find one from that lists of candidates, that's the one. Feel free to View Source if you like, or just be aware of the limitation of Twitter's (possibly deprecated) JSONP API.

我的问题是我想要一条推文,特别是第一条原始的,非本地的,未回复的推文。 我通过采用BarneyB的@ reply-filtering代码并添加了打破循环的检查来解决了这一问题。 我向Twitter请求5条推文,但是一旦我从候选人列表中找到一条,那便是那条。 如果愿意,可以随时查看源代码,或者只是知道Twitter的JSONP API(可能已弃用)的局限性。

It was a trivial but fun lunch hour, indeed.

确实,这是一个琐碎但有趣的午餐时间。

UPDATE: Great comment below from Dave Ward. He points out that I could have my cake and eat it too by using the new API and a "include_rts" flag like this:

更新:以下是Dave Ward的精彩评论。 他指出,通过使用新的API和如下的“ include_rts”标志,我也可以吃蛋糕:

https://api.twitter.com/1/statuses/user_timeline.json?screen_name=shanselman&include_rts=true&count=10&callback=twitterCallback2

https://api.twitter.com/1/statuses/user_timeline.json?screen_name=shanselman&include_rts=true&count=10&callback=twitterCallback2

Thanks Dave!

谢谢戴夫!

翻译自: https://www.hanselman.com/blog/how-to-add-tweets-to-your-blog-and-debugging-basic-javascript-why-did-twittercomjavascriptblogger-jsonp-widget-stop-working

blogger

blogger_如何在博客中添加推文并调试基本JavaScript:为什么Twitter.com/JavaScript/Blogger JSONP Widget停止工作?...相关推荐

  1. 博客中添加动漫妹子,总有一个适合你,嘿嘿嘿!

    常喜欢逛博客的你,是不是会碰到一些有意思的东西,有很多博客网站都有一个卡通人物,它一直盯着你鼠标移动的地方,俗称看板娘. 是不是好想拥有她? 今天就来讲讲如何在自己的博客中添加类似的功能.如果你的数学 ...

  2. 【转】在你的博客中添加Google地图(Use Google Map API On Your Bolg)

    在你的博客中添加Google地图(Use Google Map API On Your Bolg) *+申请一组 Google Maps API Key 在使用 Google Maps API 之前, ...

  3. 2020-04-19-如何在博客中添加视频链接

    layout title subtitle date author preview-img header-img catalog istop music-id music-idfull apserve ...

  4. hexo博客中添加categories分类

    title: hexo博客中添加categories分类 date: 2020-04-01 16:45:16 tags: hexo categories: 学习 方法如下: 在根目录下scaffold ...

  5. 如何在博客中添加Aplayer音乐播放器

    前言 是否有一首音乐,前奏一响起,让你灵魂不自主的颤栗.音乐就像老胶卷,每个旋律,每句歌词,都承载着每个人的往事回忆和情愫感受. 我收藏了好多的音乐,奈何好多音乐受版权限制,需要购买VIP才能听,还有 ...

  6. jekyll个人博客中添加音乐播放插件

    方法一: 环境要求 jekyll 七牛 开始使用 step1 首先下载这个文件open-embed.html,右键,另存为Html;下面是源码,也可以复制保存下面的源码; <style> ...

  7. 在CSDN博客中添加量子恒道统计功能的做法

    作者:朱金灿 来源:http://blog.csdn.net/clever101 什么是量子恒道统计?量子恒道统计是一套免费的网站流量统计分析系统.致力于为所有个人站长.个人博主.所有网站管理者.第三 ...

  8. 如何在新浪博客中添加JavaScript代码

    新浪博客中不能包含JavaScript代码和IFrame的代码.如果要在博客中加入像Google的广告之类的JavaScript代码,一般的方法是不行的. 今天试了一上午,搞定了. 原理:将JavaS ...

  9. hexo博客中添加音乐播放器

    1. 简介 本篇文章是介绍基于网易云iframe插件在hexo博客中加装音乐播放器的方法,无需安装任何额外插件. 2.安装步骤 在网易云音乐中打开你想要插入的音乐页面,点击 生成外联播放器. 在网页中 ...

最新文章

  1. 作者免费分享自己论文也不行,知名学术社交网站被判侵权,此前已下架20万余篇论文...
  2. Myeclipse中遇到Unauthorized
  3. 长安大学二级c语言考试题,长安大学03-04C语言A卷试题
  4. css3轮播不用jpuery_15款效果很酷的最新jQuery/CSS3特效
  5. 分享一批国内常用的tracker地址
  6. 函数指针与指针函数(C++工厂设计最喜欢用这个)
  7. DNSChanger路由器DNS劫持木马 新版本正在攻击家庭及小企业路由器 企图推送广告...
  8. 【6】测试用例设计-输入域+输出域+异常分析+错误出错法
  9. 关于QT中的音频通信问题
  10. UBUNTU安装和卸载软件
  11. 下载Django中文官方文档
  12. 玩转 ESP32 + Arduino (二十二) SIM800L上传数据到阿里IOT(温湿度和LBS)(NTP对时)
  13. 足球foteball英文
  14. winform小程序-随机抽奖软件
  15. win10忘记redis密码
  16. Mysql知识梳理,学习笔记
  17. mysql变量环境配置文件_Day44 Mysql环境变量、配置文件(2)
  18. 使用JMETER进行REST API测试(分步指南)
  19. ANSI colored Python logging — Gist
  20. 《配电网自动化技术》第一章

热门文章

  1. 如何掌握高效学习方法,提高学习效率?
  2. 地方征信平台:太原企业征信通过备案正式运行
  3. HTML11 表格和表单
  4. 无线通信中的TD系统(TD-LTE)
  5. 楼教主男人八题(第一题)
  6. 【元胞自动机】激进策略元胞自动机三车道(开放辅路,软件园影响)交通流模型matlab源码
  7. 西夏文可用电脑录入了【ZZ】
  8. 05丨指标关系:你知道并发用户数应该怎么算吗?
  9. Win10恢复自带应用的方法
  10. 中国工程院新增选54名院士