Memsource-API/index.php

38 lines
1.3 KiB
PHP
Raw Normal View History

2019-02-27 04:41:46 +00:00
<?php
session_start();
if (!isset($_SESSION['token'])) {
header('Location: /oauth.php');
2019-02-27 04:41:46 +00:00
}
$resource = getResource($_SESSION['token']);
2019-03-02 00:25:19 +00:00
// print_r($resource); die();
echo "<br>\nuserName: {$resource['user']['userName']}";
echo "<br>\nName: {$resource['user']['firstName']}";
echo "<br>\nLast name: {$resource['user']['lastName']}";
echo "<br>\nEmail: {$resource['user']['email']}";
echo "<br>\nEdition: {$resource['edition']['name']}";
echo "<br>\nOrganization: {$resource['organization']['name']}";
2019-02-27 04:41:46 +00:00
// we can now use the access_token as much as we want to access protected resources
function getResource($access_token)
{
$test_api_url = 'https://cloud.memsource.com/web/api2/v1/auth/whoAmI';
2019-03-02 00:25:19 +00:00
// $test_api_url = 'https://cloud.memsource.com/web/api2/v1/projects';
// $test_api_url = 'https://cloud.memsource.com/web/api2/v1/projects/zFbwYXoMLoa3cJ60Vvldo2?purge=true';
2019-02-27 04:41:46 +00:00
$header = ["Authorization: Bearer {$access_token}"];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $test_api_url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_RETURNTRANSFER => true
2019-03-02 00:25:19 +00:00
// CURLOPT_CUSTOMREQUEST => 'DELETE' <-- This is how to send a DELETE request
2019-02-27 04:41:46 +00:00
]);
$response = curl_exec($curl);
curl_close($curl);
return json_decode($response, true);
}