簡體   English   中英

Google Feed API-無法從Feed中加載圖片

[英]Google Feed API - Failed to load images from Feed

我正在嘗試使用Google Feed Api在網站中加載多個Feed。 我在將圖像加載到供稿時遇到問題,無法找到解決方案。 有人可以幫我嗎? 下面是一個codepen。

供稿具有以下標記:

<img>http://img.ephoto.sk/images/content/articles/c285367e4e39cfa8056f2c95ec715f76c1e758af.jpg</img>

JS代碼:

function parseFeed(url, container) {
$.ajax({
    url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=5&callback=?&q=' + encodeURIComponent(url), // "num=5" will show 5 articles
    dataType: 'json',
    success: function (data) {
        // log object data in console
        console.log(data.responseData.feed);
        // for each entry... *
        $.each(data.responseData.feed.entries, function (key, value) {
            var title = '<li><a class="title" href="' + value.link + '" target="_blank">' + value.title + '</a></li>';
                    var image = '<img class="thumbnail" src="' + value.img + '">';
            var entry = '<div class="entry"><ul>' + image + title +  '</ul></div>';
            // * append entire entry in container
            $(container).append(entry);
        });
    },
    // if there's an error... *
    error: function (errorThrown) {
        // * log error message in console
        console.log(errorThrown);
        // * show error message
        alert('Niekde vo feede sa vyskytla chyba.');
    }
});
}
$(document).ready(function () {
    parseFeed('http://feeds.feedburner.com/FotoportlEphotosk-FotoFotografieFotoaparty', '#ephoto');
});

Codepen: http ://codepen.io/MichalSK/pen/rVEwPy

還有什么解決方案可以使此代碼與此標記一起使用?

<image>
<url>http://...</url>
<title>Lorem ipsum</title>
<pubDate>Wed, 19 Aug 2015 13:00:00 +0200</pubDate>
<link>http://...</link>
</image>

希望對其他希望使用Google Feed Api的人也有所幫助。

您確定在data.responseData.feed.entries參數中具有img參數嗎? 您的value.link正在從data.responseData.feed.entries參數中獲取鏈接參數的值,但是您沒有“ img”參數來為其獲取值

var image = '<img class="thumbnail" src="' + value.img + '">';

因此,在獲取未定義的參數之前,需要將圖像的存儲鏈接存儲在正在加載的data對象中。

下面的代碼顯示了圖像,因為為這些圖像定義了鏈接。 data.responseData.feed.entries.value ,沒有img參數可通過其值獲取鏈接

 function parseFeed(url, container) { $.ajax({ url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=5&callback=?&q=' + encodeURIComponent(url), // "num=5" will show 5 articles dataType: 'json', success: function (data) { // log object data in console console.log(data.responseData.feed); // for each entry... * $.each(data.responseData.feed.entries, function (key, value) { //valid link to image source var img = "http://rocketdock.com/images/screenshots/Debian-Logo.png" var title = '<li><a class="title" href="' + value.link + '" target="_blank">' + value.title + '</a></li>'; var image = '<img class="thumbnail" src="' + img + '">'; var entry = '<div class="entry"><ul>' + image + title + '</ul></div>'; // * append entire entry in container $(container).append(entry); }); }, // if there's an error... * error: function (errorThrown) { // * log error message in console console.log(errorThrown); // * show error message alert('Niekde vo feede sa vyskytla chyba.'); } }); } $(document).ready(function () { parseFeed('http://feeds.feedburner.com/FotoportlEphotosk-FotoFotografieFotoaparty', '#ephoto'); }); 
 html,body { background-color:#222; color:#fff; font-family:"Noto Sans", sans-serif; font-size:1em; font-weight:400; line-height:1.45; } a{ color: #fff; text-decoration: none; } img{ width:50px; height:50px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <div id="container"> <div id="ephoto"></div> </div> 

從控制台檢查數據,找不到img參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM