Closed windowsales closed 3 years ago
Hi there, in the README, it would be nice to include a runnable node example. Here is how I got it working:
// This is the main Node.js source code file of your actor.
// Import Apify SDK. For more information, see https://sdk.apify.com/
const Apify = require('apify');
Apify.main(async () => {
// Prepare actor input
/**
* Actor code
*/
const input = {
postsFromDate: "5 years",
searchKeywords: "bitcoin",
extendOutputFunction: async ({ data, item, page, request, customData }) => {
return item;
},
extendScraperFunction: async ({ page, request, requestQueue, customData, Apify, extendOutputFunction }) => {
},
customData: {},
proxyConfiguration: {
useApifyProxy: true
}
};
// Run the actor
const run = await Apify.call('bernardo/youtube-scraper', input,{'token':'<YOUR TOKEN>'});
// Print actor output (if any)
console.log('Output');
console.dir(run.output);
// Fetch and print actor results from the run's dataset (if any)
console.log('Results from dataset');
const dataset = await Apify.openDataset(run.defaultDatasetId, { forceCloud: true });
await dataset.forEach(async (item, index) => {
console.log(JSON.stringify(item));
});
});
make sure you use await inside an async function, like this:
(async () => {
await ...
})()
top-level await is a feature that is only available in Node 14+
Your example "const run = await Apify.call('bernardo/youtube-scraper', input);" produces an error " await is only valid in async function"