2016-04-02 34 views
0

我使用FeedEk的jQuery插件,它使用YQL API,嘗試和顯示器有3個RSS提要。的jQuery與YQL RSS訂閱隨機返回null

大多數時候事情都很好,但每過一段時間,我都會從三種飼料中的一種獲得results: null,但通常是第二種和第三種飼料,很少是第一種飼料。我檢查了飼料本身和他們沒有表現出任何的問題,我也測試了它在雅虎控制檯,它不顯示的問題。 這不是一個呼叫限制問題,因爲我幾乎沒有打300電話從我的IP,同時測試了一天。

我啓用的診斷,我可以看到的唯一的事情是不同與result: null飼料是它在info部分下面的消息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爲失敗結果

/**/ 
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 
    } 
}); 

回答

1

做一些更多的試驗是唯一的解決辦法我能想出之後是,YQL不喜歡需要較長時間才能送達飼料。慢,高需求的飼料,他們都有可能出現這個問題的人。

我有一種感覺,這可能是因爲API代碼有一個超時其中代碼的權力,在控制檯不開心地等待,因此爲什麼它的工作原理與一個而不是其他。

不幸的是這似乎是唯一的解決辦法是要小心你使用的飼料。