Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/458.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用AngularJS使用google feed API获得混合格式_Javascript_Json_Angularjs_Feed - Fatal编程技术网

Javascript 如何使用AngularJS使用google feed API获得混合格式

Javascript 如何使用AngularJS使用google feed API获得混合格式,javascript,json,angularjs,feed,Javascript,Json,Angularjs,Feed,我将google的FeedAPI与AngularJS一起使用,我需要以混合格式(json和xml)获取提要数据。我正在使用以下代码通过Ngresse调用Google的Api,我一直在尝试将方法和回调标记更改为混合格式,但无法使其正常工作。这里谷歌解释了如何使用它,但我不知道如何将它应用到AngularJS 您可以简单地将其添加到查询中的参数中。我修改了您的示例,将输出格式设置为混合模式 .factory('FeedLoader', function ($resource) { retur

我将google的FeedAPI与AngularJS一起使用,我需要以混合格式(json和xml)获取提要数据。我正在使用以下代码通过Ngresse调用Google的Api,我一直在尝试将方法和回调标记更改为混合格式,但无法使其正常工作。这里谷歌解释了如何使用它,但我不知道如何将它应用到AngularJS


您可以简单地将其添加到查询中的参数中。我修改了您的示例,将输出格式设置为混合模式

.factory('FeedLoader', function ($resource) {
    return $resource('http://ajax.googleapis.com/ajax/services/feed/load', {}, {
        fetch: { method: 'JSONP', params: {v: '1.0', callback: 'JSON_CALLBACK', output: 'json_xml'} }
    });
})

我需要解析enclosure标记以获取url图像。假设我应该得到json+xml代码的混合输出,但是当我尝试解析它时,我从Enclosure标记中得到了一个未定义的值。我这样做就像我在这篇文章中看到的一样。此外,我尝试使用混合格式手动编写url,但没有成功。这是我的全部密码。我怎么知道我得到了混合json输出

var feeds = [];
var entryImageUrl = [];

angular.module('starter.controllers', ['ngResource','ngLocale'])

.factory('FeedLoader', function ($resource) {
        return $resource('http://ajax.googleapis.com/ajax/services/feed/load', {}, {
            fetch: { method: 'JSONP', params: {v: '1.0', callback: 'JSON_CALLBACK', output: 'json_xml'} }
        });
})

.service('FeedList', function ($rootScope, FeedLoader) {
    this.get = function() {
        var feedSources = [
            {title: 'Heraldo De Barbate', url: 'http://www.heraldodebarbate.es/rss/last'},
        ];
        if (feeds.length === 0) {
            for (var i=0; i<feedSources.length; i++) {
                FeedLoader.fetch({q: feedSources[i].url, num: 10}, {}, function (data) {
                    var feed = data.responseData.feed;
                    **var entryImageUrl = feed.xmlNode.getElementsByTagName("enclosure")[i].getAttribute("url");**
                    feeds.push(feed);
                });
            }
        }
        return feeds;
    };
})

.controller('FeedCtrl', function ($scope, FeedList,$timeout) {

  $scope.update = function(){
    $scope.feeds = FeedList.get();
    $scope.$on('FeedList', function (event, data) {
        $scope.feeds = data;
        // $scope.entryImageUrl 
        console.log(feeds);
    });
    $timeout(function() {
      $scope.$broadcast('scroll.refreshComplete');
    }, 500);    
  }
})
var提要=[];
变量entryImageUrl=[];
angular.module('starter.controllers',['ngResource','ngLocale'])
.factory('FeedLoader',函数($resource){
返回$resource('http://ajax.googleapis.com/ajax/services/feed/load', {}, {
fetch:{method:'JSONP',params:{v:'1.0',callback:'JSON_callback',output:'JSON_xml'}
});
})
.service('FeedList',函数($rootScope,FeedLoader){
this.get=函数(){
var馈线源=[
{标题:'Heraldo De Barbate',url:'http://www.heraldodebarbate.es/rss/last'},
];
如果(feeds.length==0){
对于(var i=0;i
var feeds = [];
var entryImageUrl = [];

angular.module('starter.controllers', ['ngResource','ngLocale'])

.factory('FeedLoader', function ($resource) {
        return $resource('http://ajax.googleapis.com/ajax/services/feed/load', {}, {
            fetch: { method: 'JSONP', params: {v: '1.0', callback: 'JSON_CALLBACK', output: 'json_xml'} }
        });
})

.service('FeedList', function ($rootScope, FeedLoader) {
    this.get = function() {
        var feedSources = [
            {title: 'Heraldo De Barbate', url: 'http://www.heraldodebarbate.es/rss/last'},
        ];
        if (feeds.length === 0) {
            for (var i=0; i<feedSources.length; i++) {
                FeedLoader.fetch({q: feedSources[i].url, num: 10}, {}, function (data) {
                    var feed = data.responseData.feed;
                    **var entryImageUrl = feed.xmlNode.getElementsByTagName("enclosure")[i].getAttribute("url");**
                    feeds.push(feed);
                });
            }
        }
        return feeds;
    };
})

.controller('FeedCtrl', function ($scope, FeedList,$timeout) {

  $scope.update = function(){
    $scope.feeds = FeedList.get();
    $scope.$on('FeedList', function (event, data) {
        $scope.feeds = data;
        // $scope.entryImageUrl 
        console.log(feeds);
    });
    $timeout(function() {
      $scope.$broadcast('scroll.refreshComplete');
    }, 500);    
  }
})