Giter Club home page Giter Club logo

php-snapchat's Introduction

Snapchat for PHP

Build Status

This library is built to communicate with the Snapchat API. It was nearly feature complete and lacks some newer functionality available in the latest versions of the official apps (stories, text messages, and "chat").

It's similar to the excellent Snaphax library built by Thomas Lackner <@tlack>, but the approach is different enough that I figured it deserved its own repo.

It now also supports storing the authentication key between requests, so you don't have to hammer Snapchat with your login requests and get blocked. Look futher down the page for that.

We love it when developers add new features, fix bugs, and submit pull requests. (We need more pull requests!)

Usage

Include src/snapchat.php via require_once or Composer or whatever, then:

<?php

// Log in:
$snapchat = new Snapchat('username', 'password');

// Get your feed:
$snaps = $snapchat->getSnaps();

// Get your friends' stories:
$snaps = $snapchat->getFriendStories();

// Download a specific snap:
$data = $snapchat->getMedia('122FAST2FURIOUS334r');
file_put_contents('/home/jorgen/snap.jpg', $data);

// Download a specific story:
$data = $snapchat->getStory('[story_media_id]', '[story_key]', '[story_iv]');

// Download a specific story's thumbnail:
$data = $snapchat->getStoryThumb('[story_media_id]', '[story_key]', '[thumbnail_iv]');

// Mark the snap as viewed:
$snapchat->markSnapViewed('122FAST2FURIOUS334r');

// Mark the story as viewed:
$snapchat->markStoryViewed('[story_id]');

// Screenshot!
$snapchat->markSnapShot('122FAST2FURIOUS334r');

// Upload a snap and send it to me for 8 seconds:
$id = $snapchat->upload(
	Snapchat::MEDIA_IMAGE,
	file_get_contents('/home/jorgen/whatever.jpg')
);
$snapchat->send($id, array('jorgenphi'), 8);

// Upload a video story:
$id = $snapchat->upload(
	Snapchat::MEDIA_VIDEO,
	file_get_contents('/home/jorgen/whatever.mov')
);
$snapchat->setStory($id, Snapchat::MEDIA_VIDEO);

// Destroy the evidence:
$snapchat->clearFeed();

// Find friends by phone number:
$friends = $snapchat->findFriends(array('18006492568', '7183876962'));

// Get a list of your friends:
$friends = $snapchat->getFriends();

// Add some people as friends:
$snapchat->addFriends(array('bill', 'bob'));

// Add someone you forgot:
$snapchat->addFriend('bart');

// Get a list of the people you've added:
$added = $snapchat->getAddedFriends();

// Find out who Bill and Bob snap the most:
$bests = $snapchat->getBests(array('bill', 'bob'));

// Set Bart's display name:
$snapchat->setDisplayName('bart', 'Barty');

// Block Bart:
$snapchat->block('bart');

// Unblock Bart:
$snapchat->unblock('bart');

// Delete Bart entirely:
$snapchat->deleteFriend('bart');

// You only want your friends to be able to snap you:
$snapchat->updatePrivacy(Snapchat::PRIVACY_FRIENDS);

// You want to change your email:
$snapchat->updateEmail('[email protected]');

// Log out:
$snapchat->logout();

?>

How to stop getting blocked by Snapchat

This example will show you how to log into an account and store the auth key between requests. This is just an example and should not be deployed to production (you need to keep that auth key secret!)

//Set your own login info here. 
$username = 'YourSnapChatUsernameHere';
$password = 'YuorSnapChatPasswordHere';

$snapchat = null;
/*
Check if the auth file exists.
Remember the auth token is different for each user you access
You should probably also store this somewhere safe!!
Outside your webroot at least.....
*/
$authFilePath = __DIR__.'/auth_token.txt';
if(file_exists($authFilePath))
{
	//Username, password as null, and grab the exisiting token from disk.
	$snapchat = new Snapchat($username, null, file_get_contents($authFilePath));
	echo 'We logged in with an existing auth token! :D<br />', PHP_EOL;
}
else
{
	//Log in the old fashioned way.
	$snapchat = new Snapchat($username, $password);
	echo 'We logged in the old fashioned way! :(<br />', PHP_EOL;
}

//Check if we failed to log in succesfully
if(!$snapchat->isLoggedIn())
{
	die("Could not log into snapchat!");
}
//Store the auth token on disk so we don't have to log in again and again.
file_put_contents($authFilePath, $snapchat->getAuthToken());

// Get your information. 
$snaps = $snapchat->getUpdates();
//var_dump($snaps); //If you want to see the raw data
echo 'Your birthday is: ', $snaps->birthday, ' <br />', PHP_EOL;

Documentation

There is none, but I tried to mark up the code well enough to make up for it. Error handling is pretty weak, so watch for that.

License

MIT

php-snapchat's People

Contributors

dstelljes avatar jorgenphi avatar bullshit avatar kartiktalwar avatar sgneitzke avatar hisham-albeik avatar hspdev avatar mayankmahajan24 avatar jesperlindstrom avatar geczy avatar

Watchers

James Cloos avatar Elijah Harmon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.