首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Feed API -无法从Feed加载图像

Google Feed API -无法从Feed加载图像
EN

Stack Overflow用户
提问于 2015-08-21 00:11:22
回答 1查看 218关注 0票数 0

我正在尝试使用Google feed Api在一个网站上加载多个提要。我有问题加载图像到我的馈送,无法找到解决方案。有谁能帮我吗?下面是一个codepen。

提要有这样的标记:

代码语言:javascript
复制
<img>http://img.ephoto.sk/images/content/articles/c285367e4e39cfa8056f2c95ec715f76c1e758af.jpg</img>

JS代码:

代码语言:javascript
复制
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

有没有什么解决方案可以让这段代码与这个标记一起工作?

代码语言:javascript
复制
<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的人。

EN

回答 1

Stack Overflow用户

发布于 2015-08-21 00:36:07

您确定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参数

代码语言:javascript
复制
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');
});
代码语言:javascript
复制
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;
  }
代码语言:javascript
复制
<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参数。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32123250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档