2014-08-31 46 views
0

我使用谷歌的饲料API与AngularJS和我需要得到我的饲料数据混合格式(json & xml)。我使用下面的代码通过ngResurce调用Google的Api,我一直在尝试将方法和回调标记更改为MIXED_FORMAT,但我无法使其工作。这里谷歌解释了如何使用它,但我不知道如何将其应用到AngularJS https://developers.google.com/feed/v1/devguide#resultMixed如何使用谷歌饲料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'} } 
    }); 
}) 

回答

2

你可以简单地把它添加到您的查询的PARAMS想法。我修改了您的示例以将输出格式设置为混合模式。

.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'} } 
    }); 
}) 
+0

非常感谢你,现在我明白它是如何工作的 – mhkore 2014-09-09 21:45:46

0

我需要解析机箱标签以获取url图像。假设我应该使用json + xml代码来获得MIXED OUTPUT,但是当我尝试解析它时,我从enclousure标记中得到了一个未定义的值。我这样做就像我在这篇文章Google Feed Loader API ignoring XML attributes。看到的。此外,我试图获得混合格式手动编写的网址,但它不起作用。有我的整个代码。我怎么知道我得到混合的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);  
    } 
})