I try to connect Youtube Data API with Node.js in Sails.js, but I've a problem with "fs.readFile" function.
When I launch service it returns "undefined".
Here is my code for YoutubeService :
module.exports = {
callYoutubeApi: function (req, res) {
// Load client secrets from a local file.
fs.readFile('api/services/client_secret.json', function processClientSecrets(err, content) {
if (err) {
sails.log('Error loading client secret file: ' + err);
return "error";
}
// Authorize a client with the loaded credentials, then call the YouTube API.
sails.log('123');
return YoutubeService.authorize(JSON.parse(content), YoutubeService.getChannel);
});
},
The call in my controller :
channelData = YoutubeService.callYoutubeApi();
sails.log(channelData);
The error :
debug: undefined
debug: 123
I think the call is not working and it can't read the "processClientSecrets" function.
If someone have an idea to help me thanks !
via Benjamin Arthuys
No comments:
Post a Comment