Does Google Feed API enable access via Node.js?

前提是你 提交于 2019-12-13 04:24:43

问题


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


来源:https://stackoverflow.com/questions/22821390/does-google-feed-api-enable-access-via-node-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!