Skip to content

Instantly share code, notes, and snippets.

@itayher
Created October 18, 2016 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itayher/50f932d863df60e61f08ea04359aa5ee to your computer and use it in GitHub Desktop.
Save itayher/50f932d863df60e61f08ea04359aa5ee to your computer and use it in GitHub Desktop.

Check access_token is valid

HttpRequest

<?php

$request = new HttpRequest();
$request->setUrl('https://api.backand.com/1/objects/action/users/1');
$request->setMethod(HTTP_METH_GET);

$request->setQueryData(array(
  'name' => 'isValid'
));

$request->setHeaders(array(
  'cache-control' => 'no-cache',
  'authorization' => 'bearer 5kp0g3qjp-4G--usoledmrEdcrBkiY0F9P3AJo7kf-4HDVf5v6xdXmXlSpW4Q8uxGl28IFa_uRsZvueFYnm5BqnJ548j1KX-xpNMtKD9uvMr8slSMMRJrPiwqV67ESpg1fBgxvT9h70M_9T0kTsVnBbD9gK5wTdUEV-QEyTvSMOtbnoAZoV5j1zzWMopETjyMeO010weCWOoxZ6SPzLXaJ1eOsLRUupV4yBGPO1FxZtfg9SuaHRvGqYQZSFmkS3RpegBHNFgzw63mg'
));

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

PHP cURL

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.backand.com/1/objects/action/users/1?name=isValid",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "authorization: bearer Co-_nxJr5kp0g3qjp-4G--usoledmrEdcrBkiY0F9P3AJo7kf-4HDVf5v6xdXmXlSpW4Q8uxGl28IFa_uRsZvueFYnm5BqnJ548j1KX-xpNMtKD9uvMr8slSMMRJrPiwqV67ESpg1fBgxvT9h70M_9T0kTsVnBbD9gK5wTdUEV-QEyTvSMOtbnoAZoV5j1zzWMopETjyMeO010weCWOoxZ6SPzLXaJ1eOsLRUupV4yBGPO1FxZtfg9SuaHRvGqYQZSFmkS3RpegBHNFgzw63mg",
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment