Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'vendor/autoload.php';
- use GuzzleHttp\Client as GuzzleClient;
- const ACCESS_TOKEN_URL = 'https://www.reddit.com/api/v1/access_token';
- const SEND_MESSAGE_URL = 'https://www.reddit.com/api/compose';
- const OAUTH_URL = 'https://oauth.reddit.com/';
- $tokenStorageKey = "phpreddit:token";
- $tokenStorageFile;
- $username = "";
- $password = "";
- $clientId = "";
- $clientSecret = "";
- $client = new GuzzleClient();
- $response = $client->post(ACCESS_TOKEN_URL, array(
- 'headers' => [
- 'User-Agent' => $userAgent
- ],
- 'query' => [
- [
- 'client_id' => $clientId,
- 'response_type' => 'code',
- 'state' => bin2hex(openssl_random_pseudo_bytes(10)),
- 'redirect_uri' => 'https://garlicoinairdrop.com/reddit_callback',
- 'duration' => 'permanent',
- 'scope' => 'save,modposts,identity,edit,flair,history,modconfig,modflair,modlog,modposts,modwiki,mysubreddits,privatemessages,read,report,submit,subscribe,vote,wikiedit,wikiread'
- ]
- ],
- 'auth' => [$clientId, $clientSecret],
- 'form_params' => [
- 'grant_type' => 'password',
- 'username' => $username,
- 'password' => $password
- ]
- ));
- echo($response->getBody() . "\n");
- $body = json_decode($response->getBody());
- $tokenType = $body->token_type;
- $accessToken = $body->access_token;
- $api_type = "json";
- $from_sr = "garlicoin";
- $subject = "Test";
- $text = "Hello World";
- $to = "pootwoot";
- $Authorization = "bearer " . $accessToken;
- $ua = "garlicoinairdrop 0.1/ by Pootwoot";
- echo($Authorization . "\n");
- echo(SEND_MESSAGE_URL . "\n");
- $response = $client->post(SEND_MESSAGE_URL, array(
- 'headers' => [
- 'User-Agent' => $ua,
- 'Authorization'=> $Authorization
- ],
- 'query' => [
- [
- 'client_id' => $clientId,
- 'api_type' => $api_type,
- 'state' => bin2hex(openssl_random_pseudo_bytes(10)),
- 'from_sr' => $from_sr,
- 'subject' => $subject,
- 'text' => $text,
- 'to' => $to,
- ]
- ],
- 'auth' => [$clientId, $clientSecret]
- ));
- echo($response->getBody() . "\n");
- ?>
Add Comment
Please, Sign In to add comment