2017 © Pedro Peláez
 

library phpredditapi

image

waffelheld/phpredditapi

  • Sunday, March 18, 2018
  • by waffelheld
  • Repository
  • 1 Watchers
  • 0 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

phpredditapi

very simple wrapper for the reddit api. currently unstable., (*1)

install

composer require waffelheld\phpredditapi:dev-master

package require guzzle >= 6.*, (*2)

usage

basic example for receiving a OAuth2 token:, (*3)

<?php
require_once __DIR__ . '/vendor/autoload.php';

$reddit = new \RedditApi\Reddit();

$state = "RANDOM_UNIQUE_STRING";
$redirectUrl = "YOUR_RETURN_URL";
$clientId = "CLIENT_ID";
    $secret = "CLIENT_SECRET";

if(!isset($_GET['code']) && !isset($_GET['state'])) {
    $endpoint = "authorize";
    $params = array(
        'client_id'         => $clientId,
        'response_type'    => 'code',
        'redirect_uri'      => $redirectUrl,
        'duration'          => 'permanent',
        'state'             => $state,
        'scope'             => 'identity,edit,flair,history,modconfig,modflair,modlog,modposts,modwiki,mysubreddits,privatemessages,read,report,save,submit,subscribe,vote,wikiedit,wikiread'
    );

    $url = $reddit->getBaseUrl();
    $url .= $endpoint.'?'.http_build_query($params);
    header('Location: '.$url);

} else {


    if($_GET['state'] !== $state){
        echo 'state not matching';
        exit;
    }
    $params = array(
        'grant_type'    => 'authorization_code',
        'code'          => $_GET['code'],
        'redirect_uri'  => $redirectUrl
    );

    $reddit->setCredentials($clientId, $secret);

    $result = $reddit->auth($params);
    //access token in $result['access_token'];
}

OAuth get endpoint

$reddit = new \RedditApi\Reddit('YOUR_TOKEN');
$result = $reddit->getAuth('api/me');

OAuth post endpoint

$reddit = new \RedditApi\Reddit('YOUR_TOKEN');
$params = array(
    //declare params
);
$result = $reddit->getAuth('api/me', $params);

for a list of endpoints see reddit api auto doku, (*4)

TODO

  • error handling

The Versions

18/03 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

by Avatar waffelheld

15/03 2018

0.1

0.1.0.0

  Sources   Download

MIT

The Requires

 

by Avatar waffelheld