Guest User

Untitled

a guest
Jan 31st, 2018
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. <?php
  2. require 'vendor/autoload.php';
  3.  
  4. use GuzzleHttp\Client as GuzzleClient;
  5.  
  6. const ACCESS_TOKEN_URL = 'https://www.reddit.com/api/v1/access_token';
  7. const SEND_MESSAGE_URL = 'https://www.reddit.com/api/compose';
  8. const OAUTH_URL = 'https://oauth.reddit.com/';
  9.  
  10. $tokenStorageKey = "phpreddit:token";
  11. $tokenStorageFile;
  12.  
  13. $username = "";
  14. $password = "";
  15. $clientId = "";
  16. $clientSecret = "";
  17. $client = new GuzzleClient();
  18.  
  19.  
  20. $response = $client->post(ACCESS_TOKEN_URL, array(
  21. 'headers' => [
  22. 'User-Agent' => $userAgent
  23. ],
  24. 'query' => [
  25. [
  26. 'client_id' => $clientId,
  27. 'response_type' => 'code',
  28. 'state' => bin2hex(openssl_random_pseudo_bytes(10)),
  29. 'redirect_uri' => 'https://garlicoinairdrop.com/reddit_callback',
  30. 'duration' => 'permanent',
  31. 'scope' => 'save,modposts,identity,edit,flair,history,modconfig,modflair,modlog,modposts,modwiki,mysubreddits,privatemessages,read,report,submit,subscribe,vote,wikiedit,wikiread'
  32. ]
  33. ],
  34. 'auth' => [$clientId, $clientSecret],
  35. 'form_params' => [
  36. 'grant_type' => 'password',
  37. 'username' => $username,
  38. 'password' => $password
  39. ]
  40. ));
  41.  
  42. echo($response->getBody() . "\n");
  43.  
  44. $body = json_decode($response->getBody());
  45.  
  46. $tokenType = $body->token_type;
  47. $accessToken = $body->access_token;
  48.  
  49. $api_type = "json";
  50. $from_sr = "garlicoin";
  51. $subject = "Test";
  52. $text = "Hello World";
  53. $to = "pootwoot";
  54. $Authorization = "bearer " . $accessToken;
  55. $ua = "garlicoinairdrop 0.1/ by Pootwoot";
  56.  
  57. echo($Authorization . "\n");
  58. echo(SEND_MESSAGE_URL . "\n");
  59.  
  60. $response = $client->post(SEND_MESSAGE_URL, array(
  61. 'headers' => [
  62. 'User-Agent' => $ua,
  63. 'Authorization'=> $Authorization
  64. ],
  65. 'query' => [
  66. [
  67. 'client_id' => $clientId,
  68. 'api_type' => $api_type,
  69. 'state' => bin2hex(openssl_random_pseudo_bytes(10)),
  70. 'from_sr' => $from_sr,
  71. 'subject' => $subject,
  72. 'text' => $text,
  73. 'to' => $to,
  74. ]
  75. ],
  76. 'auth' => [$clientId, $clientSecret]
  77. ));
  78. echo($response->getBody() . "\n");
  79. ?>
Add Comment
Please, Sign In to add comment