// Set this to true if you want to see all outgoing requests and responses from server $addback = true; //////////////////////////////// // Login $tmpPath = '/tmp/'; $snapchat = new Snapchat($username, $gEmail, $gPasswd, $debug); $snapchat->login($password); if ($addback == true) { $unconfirmed = $snapchat->getUnconfirmedFriends(); if (!is_null($unconfirmed)) { print_r($unconfirmed); foreach ($unconfirmed as $friend) { $snapchat->addFriendBack($friend); } } } $snaps = $snapchat->getSnaps(); if (!is_null($snaps)) { foreach ($snaps as $snap) { echo "Processing SNAP ID [" . $snap->id . "]<br />"; $snapchat->writeToFile('../src/snaps/' . $snap->id, $snapchat->getMedia($snap->id)); $tmpFilePath = $tmpPath . $snap->id; file_put_contents($tmpFilePath, $snapchat->getMedia($snap->id)); $snapchat->setStory($tmpFilePath, $snap->time); $snapchat->markSnapViewed($snap->id); unlink($tmpFilePath); $snapchat->sendMessage($snap->sender, "Your snap has been processed, and it should appear on this account's story. Thank you for submitting!"); echo "Processed!<br /><br />"; } } $snapchat->closeAppEvent();
private function _sendAndReceive($file, $type) { $snapchat = new Snapchat($this->users[1]['name'], $this->users[1]['pass']); $this->assertNotEquals($snapchat->auth_token, FALSE, 'Login failed for test user 1.'); $id = $snapchat->upload($type, file_get_contents($file)); $this->assertEquals(is_string($id), TRUE, ($type == Snapchat::MEDIA_IMAGE ? 'Image' : 'Video') . ' upload failed.'); $result = $snapchat->send($id, array($this->users[2]['name'])); $this->assertEquals($result, TRUE, 'Media send failed.'); // TODO $this->assertEquals($snapchat->clearFeed(), TRUE, 'Failed to clear the feed of test user 1.'); $this->assertEquals($snapchat->logout(), TRUE, 'Logout failed for test user 1.'); $snapchat = new Snapchat($this->users[2]['name'], $this->users[2]['pass']); $this->assertNotEquals($snapchat->auth_token, FALSE, 'Login failed for test user 2.'); $snaps = $snapchat->getSnaps(); $this->assertNotEquals($snaps, FALSE, 'Failed to get snap list.'); foreach ($snaps as $snap) { if ($snap->status == Snapchat::STATUS_DELIVERED && strcmp($snap->recipient, $snapchat->username) == 0) { $data = $snapchat->getMedia($snap->id); $this->assertEquals($snapchat->markSnapViewed($snap->id), TRUE, 'User 2 marked snap viewed.'); $this->assertEquals($snapchat->markSnapShot($snap->id), TRUE, 'User 2 marked screenshot.'); $this->assertEquals(is_string($data), TRUE); } } $this->assertEquals($snapchat->clearFeed(), TRUE, 'Failed to clear the feed of test user 2.'); $this->assertEquals($snapchat->logout(), TRUE, 'Logout failed for test user 2.'); }
} elseif ($item['media_type'] == 1) { //if moving video if ($config['videosallowed']) { $data = $snapchat->getMedia($item['id']); //get received snap file_put_contents('media/temp.mov', $data); //create temp file with the received sna $id = $snapchat->upload(Snapchat::MEDIA_VIDEO, file_get_contents('media/temp.mov')); //upload the temp to story $snapchat->setStory($id, Snapchat::MEDIA_VIDEO, $config['videotime']); //set story unlink("media/temp.mov"); //delete temp } } $snapchat->markSnapViewed($item['id']); //mark as viewed, just in case if ($config['send_verify_snap']) { $id = $snapchat->upload(Snapchat::MEDIA_IMAGE, file_get_contents('media/thanks.jpg')); //send verification snap $snapchat->send($id, array($item['sender']), 10); //10 seconds long } $i++; //keep going } } } } $snapchat->clearFeed(); //clear feed (will become VERY long VERY soon and break program)