带有YQL RSS Feed的jQuery随机返回null [英] jQuery with YQL RSS Feeds randomly returning null

查看:103
本文介绍了带有YQL RSS Feed的jQuery随机返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为使用YQL API的jQuery使用FeedEk插件,以尝试显示三个RSS提要.

I'm using FeedEk plugin for jQuery which uses the YQL API, to try and display three RSS feeds.

大多数时候情况都可以,但是偶尔我会从三个提要之一中得到一个results: null,但通常是第二个和第三个提要,很少是第一个.我已经检查了提要本身,并且它们没有显示任何问题,我也在Yahoo Console上进行了测试,并且没有显示问题. 这不是通话限制问题,因为在测试过程中,我每天几乎无法通过IP拨打300个电话.

Most of the time things are ok but every once in a while I will get a results: null from one of the three feeds, but usually the second and third ones to be called, very rarely the first. I have checked the feeds themselves and they are not showing any issues, I have also tested it on the Yahoo Console and it doesn't show an issue. It's not a call limit issue as I'm barely hitting 300 calls a day from my IP while testing.

我启用了诊断功能,我唯一看到的是与result: null提要不同的是,它在info部分Using encoding from response content-type header (UTF-8) as XML document does not specify encoding.

I enabled diagnostics and the only thing I can see that is different with the result: null feed is it has the following message in the info section Using encoding from response content-type header (UTF-8) as XML document does not specify encoding.

这里是我打来的电话

SELECT channel.item FROM feednormalizer WHERE output="rss_2.0" AND url ="http://feeds.arstechnica.com/arstechnica/index" LIMIT 8

这是插件代码

/*
* FeedEk jQuery RSS/ATOM Feed Plugin v3.0 with YQL API (Engin KIZIL http://www.enginkizil.com)
* http://jquery-plugins.net/FeedEk/FeedEk.html  https://github.com/enginkizil/FeedEk
* Author : Engin KIZIL http://www.enginkizil.com
*/

(function ($) {
    $.fn.FeedEk = function (opt) {
        var def = $.extend({
            MaxCount: 5,
            ShowDesc: true,
            ShowPubDate: true,
            DescCharacterLimit: 0,
            TitleLinkTarget: "_blank",
            DateFormat: "",
            DateFormatLang:"en"
        }, opt);

        var id = $(this).attr("id"), i, s = "", dt;
        $("#" + id).empty();
        if (def.FeedUrl == undefined) return;
        $("#" + id).append('<div style="width:100%;text-align:center;color:#424242;"><div class="loader"></div></div>');

        var YQLstr = 'SELECT channel.item FROM feednormalizer WHERE output="rss_2.0" AND url ="' + def.FeedUrl + '" LIMIT ' + def.MaxCount;

        $.ajax({
            url: "https://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent(YQLstr) + "&format=json&diagnostics=true&callback=?",
            dataType: "json",
            success: function (data) {
                $("#" + id).empty();
                if (!(data.query.results.rss instanceof Array)) {
                    data.query.results.rss = [data.query.results.rss];
                }
                $.each(data.query.results.rss, function (e, itm) {
                    s += '<li><div class="itemTitle">' + itm.channel.item.title + '</div>';

                    if (def.ShowPubDate){
                        dt = new Date(itm.channel.item.pubDate);
                        s += '<div class="itemDate">';
                        if ($.trim(def.DateFormat).length > 0) {
                            try {
                                moment.lang(def.DateFormatLang);
                                s += moment(dt).format(def.DateFormat);
                            }
                            catch (e){s += dt.toLocaleDateString();}
                        }
                        else {
                            s += dt.toLocaleDateString();
                        }
                        s += '</div>';
                    }
                    if (def.ShowDesc) {
                        s += '<div class="itemContent">';
                         if (def.DescCharacterLimit > 0 && itm.channel.item.description.length > def.DescCharacterLimit) {
                            s += itm.channel.item.description.substring(0, def.DescCharacterLimit) + '...';
                        }
                        else {
                            s += itm.channel.item.description;
                         }
                         s += '</div>';
                    }
                });
                $("#" + id).append('<ul class="feedEkList">' + s + '</ul>');
            }
        });
    };
})(jQuery);

最后从YQL返回失败结果的XML

And finally the XML returned from YQL for the failed result

/**/
jQuery112204319277675822377_1459586267516({
    "query": {
        "count": 0,
        "created": "2016-04-02T08:37:48Z",
        "lang": "en-US",
        "diagnostics": {
            "publiclyCallable": "true",
            "url": {
                "execution-start-time": "1",
                "execution-stop-time": "59",
                "execution-time": "58",
                "content": "http://feeds.arstechnica.com/arstechnica/index"
            },
            "info": "Using encoding from response content-type header (UTF-8) as XML document does not specify encoding.",
            "user-time": "60",
            "service-time": "58",
            "build-version": "0.2.430"
        },
        "meta": {
            "url": {
                "id": "http://feeds.arstechnica.com/arstechnica/index",
                "status": "200",
                "headers": {
                    "header": [{
                        "name": "Content-Type",
                        "value": "text/xml; charset=UTF-8"
                    }, {
                        "name": "ETag",
                        "value": "m+oG6+UhrscSbLRLhGlL3lvlwNo"
                    }, {
                        "name": "Last-Modified",
                        "value": "Sat, 02 Apr 2016 07:32:51 GMT"
                    }, {
                        "name": "Content-Encoding",
                        "value": "gzip"
                    }, {
                        "name": "Expires",
                        "value": "Sat, 02 Apr 2016 07:40:36 GMT"
                    }, {
                        "name": "Cache-Control",
                        "value": "private, max-age=0"
                    }, {
                        "name": "X-Content-Type-Options",
                        "value": "nosniff"
                    }, {
                        "name": "X-XSS-Protection",
                        "value": "1; mode=block"
                    }, {
                        "name": "Server",
                        "value": "ATS"
                    }, {
                        "name": "Date",
                        "value": "Sat, 02 Apr 2016 08:37:48 GMT"
                    }, {
                        "name": "Age",
                        "value": "0"
                    }, {
                        "name": "Connection",
                        "value": "close"
                    }, {
                        "name": "Via",
                        "value": "http/1.1 ec2.ycs.bf1.yahoo.net (ApacheTrafficServer [cSsNfU])"
                    }
                    ]
                }
            }
        },
        "results": null
    }
});

推荐答案

进行了更多的实验之后,我只能想出的解决方案是YQL不喜欢需要较长时间投放的供稿.速度慢和需求高的提要似乎是造成此问题的原因.

After doing some more experimentation that only solution I can come up with is that the YQL doesn't like feeds that take longer to be served. Slower and high demand feeds are the ones that seem to present this issue.

我感觉可能是因为API代码超时,而控制台供电的代码却没有并愉快地等待,因此为什么它只能与一种而不是另一种一起使用.

I have a feeling it might be because the API code has a timeout where the code the powers the Console doesn't and happily waits, hence why it works with one and not the other.

不幸的是,似乎唯一的解决方案是对您使用的提要要小心.

Unfortunately it would seem the only solution is to be careful with the feeds you use.

这篇关于带有YQL RSS Feed的jQuery随机返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆