Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
node-snapchat-marketing
Advanced tools
:ghost: Unoffical Node library for the Snapchat Marketing API
Snapchat Marketing API Documentation
Before you begin, you need to apply for access to the Snapchat Marketing API. Once you are approved, you will be able to register a new application in the 'Business Details' section of your Snapchat Business Account. Notice that the app gets a client ID, secret, and redirect URI required for authenticating with the API.
If you reach an error page when trying to access your Business Account, try disabling any ad-blockers you might have.
After registering your application, you need to install this module in your Node.js project:
npm install node-snapchat-marketing
In order to use this module, you have to import it in your application first:
const Snap = require('node-snapchat-marketing');
Next, initialize the Snap object with the keys you obtained from the Snapchat business dashboard:
const snap = new Snap({
client_id: '<CLIENT_ID>',
client_secret: '<CLIENT_SECRET>',
redirect_uri: '<REDIRECT_URI>',
});
To make HTTP calls, you need to create an authenticated session with the API.
To obtain an OAuth token, you have to authorize your application with the required scope. The only scope currently available is 'snapchat-marketing-api'.
You are initially required to redirect your user to an authorization URL. You can generate the authorization URL using snap.getAuthorizeUrl
. In case you are using Express, your route definition could look as follows:
app.get('/snap/authorize', function(req, res) {
var url = snap.getAuthorizeUrl('snapchat-marketing-api');
res.redirect(url);
});
The URL will lead to a page where your user will be required to login and approve access to his/her Snapchat account. In case that step was successful, Snap will issue a redirect to the redirect_uri
defined in your Snapchat business account. On that redirect, you will receive a single-use authorization code via a code
query parameter in the url.
To complete the authorization you now need to receive the callback and convert the given authorization code into an OAuth access token. You can accomplish that using snap.authorization
. This method will retrieve and store the access_token, refresh_token, and token expiration date inside the Snap object. Access tokens expire after 1800 seconds (30 minutes).
In Express - If your redirect_uri
is https://example.com/snap/callback, your route could look like:
app.get('/snap/callback', (req,res)=>{
snap.authorization({ authorization_code: req.query.code }, function(err, token){
console.log("Access token is: " + token.access_token);
console.log("Refresh token is: " + token.refresh_token);
console.log("Access token expires in: " + token.expires_in + " seconds");
res.redirect('/');
});
});
snap
instance.snap.setRefreshToken('<token>');
Now that you are authenticated, you can issue requests using the provided library methods.
For instance, to obtain a list of all available organizations associated with your account, you can use snap.organization.getAll
.
snap.organization.getAll(function(err, orgs)
{
if(err)
console.log(err);
else
console.log(orgs);
});
After getting the authorize url, the user will be redirected to the redirect url with authorization code used in the next function.
snap.getAuthorizeUrl(scope);
app.get('/snap/authorize', function(req, res) {
var url = snap.getAuthorizeUrl('snapchat-marketing-api');
res.redirect(url);
});
snap.authorization(options, callback);
app.get('/snap/callback', (req,res)=>{
snap.authorization({ authorization_code : req.query.code }, function(err, token){
console.log("Access token is: " + accessToken.access_token);
console.log("Refresh token is: " + accessToken.access_token);
console.log("Access token expires in: " + accessToken.expires_in + " seconds");
res.redirect('/');
});
});
snap.me(callback);
snap.me(function(err, user){
if(err)
console.log(err);
else
console.log(user);
})
snap.organization.getAll(options, callback);
snap.organization.getAll({ withAdAccounts: true }, function(err, orgs){
if(err)
console.log(err);
else
console.log(orgs);
});
snap.organization.getById(id, callback);
snap.organization.getById('<organization_id>', function(err, org){
if(err)
console.log(err);
else
console.log(org);
});
snap.media.createMedia(media, callback);
const newMedia = {
media: [
{ name:"Some new media", type:"VIDEO", ad_account_id: myAdAccountId },
]
}
snap.media.createMedia(newMedia, function(err, res){
if(err)
console.log(err);
});
snap.media.getAll(adAccountId, callback);
snap.media.getAll(adAccountId, function(err,media)
{
if(err)
console.log(err);
else
console.log(media);
})
Before you try to run any tests, you MUST go to test/credentials/keys.js
and fill in your app credentials.
module.exports = {
CLIENT_ID: '<your_client_id>',
CLIENT_SECRET: '<your_client_secret>',
REDIRECT_URI: '<your_redirect_uri>',
REFRESH_TOKEN:'<your_refresh_token>'
}
Then, you can execute tests using:
npm run test
FAQs
Unofficial Node library for the Snapchat Marketing API
We found that node-snapchat-marketing demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.