Skip to content

Instantly share code, notes, and snippets.

@michelalbers
Last active February 27, 2023 19:48
Show Gist options
  • Save michelalbers/7004953 to your computer and use it in GitHub Desktop.
Save michelalbers/7004953 to your computer and use it in GitHub Desktop.
A nodeJS port for the undocumented snapchat HTTP API. So far only login is implemented (which gives you all followers and snaps). You can post to any endpoint of the snapchat API though but you have to handle the response yourself. Feel free to enhance, fix and use it as you like! This is an early development stage.

Undocumented Snapchat API ported in nodeJS

Important: This is an early development stage. So far only login is implemented. You can however post to any endpoints of the API but you have to deal with the response yourself

Usage

Login

Provide a username and a password. The response of snapchat will contain the friends, the besties, the snaps and some additional information.

helpers.login(USERNAME, PASSWORD, function(res) { someCallback(); }, function(err) { someError(); });

Post to any API endpoint

The first and second hashparam are most likely helpers.static_token and helpers.nanotime(). To give maximum flexibility though, I implemented this in a configurable way:

helpers.postToSnapchatApi('/myEndPoint',{my: data}, [hashparam1, hashparam2], function(res) { someCallback(); }, function(err) { someError(); });

That's it so far. Feel free to enhance the script and remove any errors or inconsistencies.

# Snapchat HTTP API Constants and Helper functions
helpers =
api_url: "feelinsonice-hrd.appspot.com"
secret: 'iEk21fuwZApXlz93750dmW22pw389dPwOk'
static_token: 'm198sOkJEn37DjqZ32lpRu76xmw288xSQ9'
blob_encryption_key: 'M02cnQ51Ji97vwT4'
hash_pattern: '0001110111101110001111010101111011010001001110011000110001000110'
version: '6.0.0'
hash: (first,second) ->
first = helpers.secret + first
second = second + helpers.secret
crypto = require 'crypto'
hash1 = crypto.createHash 'sha256'
hash1 = hash1.update first
hash1 = hash1.digest 'hex'
hash2 = crypto.createHash 'sha256'
hash2 = hash2.update second
hash2 = hash2.digest 'hex'
getSubpart = (index,hash) ->
if hash == true
hash2.substr index,1
else
hash1.substr index,1
finalHash = ""
finalHash += getSubpart x,helpers.hash_pattern.substr(x,1) == '1' for x in [0..helpers.hash_pattern.length]
return finalHash
nanotime: () ->
now = new Date()
return now.getTime()
postToSnapchatApi: (endpoint, data, params, successCallback, errorCallback) ->
data.req_token = helpers.hash params[0], params[1]
data.version = helpers.version
console.log data
request = require 'request'
request.post
uri: 'https://' + helpers.api_url + '/bq' + endpoint
headers:
'user-agent': 'Snapchat/6.0.0 (iPhone; iOS 7.0.2; gzip)'
form: data
, (e,r, body) ->
if not e
successCallback body
else
errorCallback e
login: (username,password,successCallback,errorCallback) ->
this.postToSnapchatApi '/login', (
'username': username
'password': password
'timestamp': this.nanotime()
),[this.static_token,this.nanotime()],successCallback,errorCallback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment