npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-alerts-api

v0.6.1

Published

Google Alerts API

Downloads

325

Readme

Actions Status NPM Downloads NPM Downloads

google-alerts-api

Google Alerts API for nodejs. See tests for all features coverage.

Features

  • Creating alerts (no support for few parameters)
  • Fetching alerts
  • Modifing alerts (no support for few parameters)
  • Removing alerts

Getting started

$ npm i -S google-alerts-api
const alerts = require('google-alerts-api');

Configuration

IMPORTANT: Due to the latest changes in Google, authentication with disabled JavaScript is permited. Still, you can generate cookies on your own and reuse it later on (see how to get cookies)

alerts.configure({
    cookies: 'W3sia2V5IjoiR0FQUyIsInZhbHVlIjoiMTpCRXRtZEpjc...saGRasC==',
});

How to use

Fetch alerts:

const alerts = require('google-alerts-api');
const { HOW_OFTEN, DELIVER_TO, HOW_MANY, SOURCE_TYPE } = alerts;

alerts.configure({
    cookies: 'W3sia2V5IjoiR0FQUyIsInZhbHVlIjoiMTpCRXRtZEpjc...saGRasC==',
});

alerts.sync((err) => {
    if(err) return console.log(err);
    const alertList = alerts.getAlerts();
    alertList.forEach(alert => printAlertInfo);
});

function printAlertInfo(alert) {
    console.log('name:', alert.name);
    //'How Many' property information:
    if (alert.howMany === HOW_MANY.BEST) {
    	console.log('How many: Only the best results');
    } else if (alert.howMany === HOW_MANY.ALL) {
    	console.log('How many: All Results');
    }
}

Example alert object:

{
    name: '"Donald Trump * ISIS"',
    id: '4f94515ec736ef62:ade5b03803caa237:com:en:PL:R',
    howOften: 2, //use HOW_OFTEN enum to find out proper meaning
    sources: '...', // some of SOURCE_TYPE enum property, SOURCE_TYPE.AUTOMATIC by default
    lang: 'en',
    region: 'PL',
    howMany: 3, //use HOW_MANY enum to find out proper meaning
    deliverTo: 2, //use DELIVER_TO enum to find out proper meaning
    deliverToData: '', //email address, available when deliverTo === DELIVER_TO.MAIL
    rss: 'https://google.com/alerts/feeds/00357582442749620569/11537740808718742679' //field available, when deliverTo === DELIVER_TO.RSS
}

Modify alert (see tests for more examples):

const { HOW_OFTEN, DELIVER_TO, HOW_MANY } = alerts;

alerts.sync((err) => {
    if(err) return console.log(err);
    const alertToModify = alerts.getAlerts()[0];
    alerts.modify(alertToModify.id, {
    	name: '"(Donald OR Melania) Trump"'
    }, () => {
        alerts.sync(() => {
            const syncedAlertsList = alerts.getAlerts();
            //search in syncedAlertsList to check updated alert
        });
    });
});

function printAlertInfo(alert){
    console.log('name:', alert.name);
    //'How Many' property information:
    if (alert.howMany === HOW_MANY.BEST) {
    	console.log('How many: Only the best results');
    } else if (alert.howMany === HOW_MANY.ALL) {
    	console.log('How many: All Results');
    }
}

Available source types:

const SOURCE_TYPE = {
    AUTOMATIC,
    NEWS,
    BLOGS,
    WEB,

    NEWS_AND_BLOGS,
    NEWS_AND_WEB,
    BLOGS_AND_WEB,

    VIDEO,
    BOOKS,
    DISCUSSIONS,
    FINANCE,
};

Create alert:

alerts.sync(() => {
    const alertToCreate = {
    	howOften: HOW_OFTEN.AT_MOST_ONCE_A_DAY,
	sources: SOURCE_TYPE.AUTOMATIC, // default one
        lang: 'en',
        name: 'NodeJS AND "Chrome V8"',
        region: 'PL', // or "any", if you want "All Regions"
        howMany: HOW_MANY.BEST,
        deliverTo: DELIVER_TO.RSS,
        deliverToData: ''
    };

    alerts.create(alertToCreate, (err, alert) => {
        console.log(alert);
    });
});

Remove alert:

alerts.sync((err) => {
    const alertToRemove = alerts.getAlerts()[0];
    alerts.remove(alertToRemove.id, (err) => {
    	alerts.sync((err) => {
            const syncedAlertsList = alerts.getAlerts(); //alertToRemove does not exists here.
        });
    });   
});

Generate cookies:

You can authenticate once, and then use your cookies. Unfortunatelly it requires an additional action from you:

STEP 1: Authenticate in browser

  1. Open Chrome Browser in Incognito mode
  2. Navigate http://myaccount.google.com
  3. Log into your account

STEP 2: Find your SID, HSID, SSID cookie values

  1. Open Chrome Dev Tools
  2. Navigate Application tab, select Cookies preview for http://myaccount.google.com domain
  3. Copy SID, HSID and SSID cookie values

copy SID, HSID, SSID cookie values

STEP 3: Prepare your auth cookie string

  1. Put your SID, HSID, SSID values into value field of the code:
window.btoa(JSON.stringify(
    [{
            key: 'SID',
            value: '',
            domain: 'google.com'
        },
        {
            key: 'HSID',
            value: '',
            domain: 'google.com'
        },
        {
            key: 'SSID',
            value: '',
            domain: 'google.com'
        },
    ]
));
  1. Run this code in Console tab
  2. The output is your auth cookie string

enter image description here

  1. Put auth cookie string configuration:
const fs = require('fs')
const alerts = require('google-alerts-api')

alerts.configure({
    cookies: "your 'auth cookie string' goes here..."
});

alerts.sync((err) => {
    if(err) return console.log(err)
    const alertList = alerts.getAlerts()
});

Problem with authentication?

  • https://accounts.google.com/b/1/DisplayUnlockCaptcha (make sure you are editing settings for proper user...)
  • https://myaccount.google.com/lesssecureapps
  • review auth issues labeled issues, hope you will find an answer