0

Im using the google's feed API with AngularJS and I need to get my feed data in a mixed format (json & xml). I'm using the following code to call the Google's Api throught ngResurce, I'd been trying change the method and callback tags to MIXED_FORMAT but I couldn't make it works. Here Google explains how to use it, but I have no idea about how to apply it to AngularJS https://developers.google.com/feed/v1/devguide#resultMixed

.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 Answers 2

2

You can simply add it to the params in your query. I modified your example to set the output format to mixed mode.

.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'} }
    });
})
Sign up to request clarification or add additional context in comments.

Comments

0

I need parse the enclosure tag in order to get the url image. It's assumed I should get the MIXED OUTPUT with the json+xml code but I get a undefined value from the enclousure tag when I try parse it. I'm doing this like I saw at this post Google Feed Loader API ignoring XML attributes .In addition I tried to get the MIXED format writing the url manually but It doesn't work. There is my whole code. How could I know that Im getting the mixed json output?

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.