Does Google Feed API enable access via Node.js?

2019-09-19 08:37发布

I want to use Google Feed API from a server (Node.js). I have already installed the googleapis module. My code is:

// parts omitted
var googleapis = require('googleapis');
// parts omitted
googleapis.discover('feeds').execute(function(err, client) {
var feed = new google.feeds.Feed('http://rss.lemonde.fr/c/205/f/3050/index.rss');
});
// parts omitted

But Node.js console tells me that "google is not defined". Any idea of the problem and solution?

2条回答
欢心
2楼-- · 2019-09-19 08:55

to access Google Feed API using Node.js, you should try the google-feed-api module as explained here:

https://www.npmjs.org/package/google-feed-api

Hope it helps!

Edit:

I tried this with your URL and worked fine:

var gfeed = require('google-feed-api');
var feed = new gfeed.Feed('http://rss.lemonde.fr/c/205/f/3050/index.rss');
feed.listItems(function(items){
    console.log(items);
});
查看更多
倾城 Initia
3楼-- · 2019-09-19 09:09

It's because google is literally not defined. I don't know very much about that module, but I think that instead of using the google var you should use client , because that's what the execute function returns.
So the code would be:

// parts omitted
var googleapis = require('googleapis');
// parts omitted
googleapis.discover('feeds').execute(function(err, client) {
var feed = new client.feeds.Feed('http://rss.lemonde.fr/c/205/f/3050/index.rss');
});
// parts omitted
查看更多
登录 后发表回答