Skip to content

Instantly share code, notes, and snippets.

@pdehaan
Created August 31, 2016 17:46
Show Gist options
  • Select an option

  • Save pdehaan/56700418071713b46a806cd5431ba95a to your computer and use it in GitHub Desktop.

Select an option

Save pdehaan/56700418071713b46a806cd5431ba95a to your computer and use it in GitHub Desktop.
Usage for Google SafeBrowsing v4 API
const API_KEY = 'xxx';
const promisify = require('es6-promisify');
const safebrowsing = require('googleapis').safebrowsing('v4');
const _findThreatMatches = promisify(safebrowsing.threatMatches.find);
const pkg = require('./package.json');
const client = {
clientId: pkg.name,
clientVersion: pkg.version
};
function findThreatMatches(urls=[], client) {
const resource = {
client,
threatInfo: {
platformTypes: ['ANY_PLATFORM'],
threatEntries: urls.map(url => ({url})),
threatEntryTypes: ['URL'],
threatTypes: ['MALWARE', 'SOCIAL_ENGINEERING', 'POTENTIALLY_HARMFUL_APPLICATION', 'UNWANTED_SOFTWARE']
}
};
return _findThreatMatches({
key: API_KEY,
resource
});
}
findThreatMatches(['http://twitter.com', 'https://facebook.com', 'http://cnn.com'], client)
.then(data => console.log(data))
.catch(err => console.error(err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment