Ejemplo n.º 1
0
<?php

require '../vendor/autoload.php';
require 'credentials.php';
use JonathanTorres\MediumSdk\Medium;
$credentials['redirect-url'] = 'http://localhost:8888/create_post.php';
$medium = new Medium($credentials);
if (isset($_GET['code'])) {
    session_start();
    $code = $_GET['code'];
    $medium->authenticate($code);
    $_SESSION['user'] = $medium->getAuthenticatedUser();
    $_SESSION['code'] = $code;
    $_SESSION['token'] = $medium->getAccessToken();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    session_start();
    $authenticatedUser = $_SESSION['user'];
    $data = ['title' => $_POST['title'], 'contentFormat' => 'html', 'content' => $_POST['content'], 'publishStatus' => 'draft'];
    $medium->setAccessToken($_SESSION['token']);
    $post = $medium->createPost($authenticatedUser->data->id, $data);
}
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Create post</title>
Ejemplo n.º 2
0
<?php

require '../vendor/autoload.php';
require 'credentials.php';
use JonathanTorres\MediumSdk\Medium;
$medium = new Medium($credentials);
$medium->authenticate($_GET['code']);
$authenticatedUser = $medium->getAuthenticatedUser();
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Callback</title>

    <!-- Bootstrap -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
        <div class="row">
            <h1>Authenticated user details</h1>
            <hr>
            <pre>
                <?php 
print_r($authenticatedUser);
?>
            </pre>
Ejemplo n.º 3
0
<?php

require '../vendor/autoload.php';
require 'credentials.php';
use JonathanTorres\MediumSdk\Medium;
$medium = new Medium($credentials);
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Authentication</title>

    <!-- Bootstrap -->
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
        <div class="row">
            <h1>Authentication</h1>
            <hr>
            <a href="<?php 
echo $medium->getAuthenticationUrl();
?>
" class="btn btn-primary btn-large">Authenticate with Medium</a>
        </div>
    </div>