可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
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); });
回答2:
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