<?php /** * Example of usage Yandex\Disk package * * @author Alexander Mitsura * @created 15.10.13 10:32 */ $settings = (require_once '../../settings.php'); use Yandex\OAuth\OAuthClient; $client = new OAuthClient($settings['global']['clientId']); if (isset($_COOKIE['yaAccessToken'])) { $directory = $_POST['directory']; $client->setAccessToken($_COOKIE['yaAccessToken']); // XXX: how it should be (using user access token) //$diskClient = new \Yandex\Disk\DiskClient($client->getAccessToken()); // XXX: how it is now (using magic access token) $diskClient = new \Yandex\Disk\DiskClient($client->getAccessToken()); $diskClient->setServiceScheme(\Yandex\Disk\DiskClient::HTTPS_SCHEME); header('Content-type: application/json'); $response = []; if ($diskClient->createDirectory($directory)) { $response['status'] = 'OK'; } echo json_encode($response); }
<div class="col-md-8"> <ol class="breadcrumb"> <li><a href="/examples">Examples</a></li> <li><a href="/examples/OAuth">OAuth</a></li> <li class="active">callback</li> </ol> <p> <a href="index.php"><Назад</a> </p> <?php use Yandex\OAuth\OAuthClient; $client = new OAuthClient($settings['global']['clientId'], $settings['global']['clientSecret']); if (isset($_COOKIE['yaAccessToken'])) { $client->setAccessToken($_COOKIE['yaAccessToken']); echo '<p>PHP: Access token from cookies is ' . htmlentities($client->getAccessToken()) . '</p>'; } /** * There are two ways to get an access token from Yandex OAuth API. * First one is to get in browser after # symbol. It's handled above with JS and PHP. * Second one is to use an intermediate code. It's handled below with PHP. * * This file implements both cases because the only one callback url can be set for an application. * */ if (isset($_REQUEST['code'])) { try { $client->requestAccessToken($_REQUEST['code']); } catch (\Yandex\OAuth\Exception\AuthRequestException $ex) { echo '<p class="text-danger">' . $ex->getMessage() . '</p>'; }