Skip to content

Instantly share code, notes, and snippets.

@Tobur
Last active December 25, 2015 14:29
Show Gist options
  • Save Tobur/6991478 to your computer and use it in GitHub Desktop.
Save Tobur/6991478 to your computer and use it in GitHub Desktop.
protected function execute($link, $parameters = array(), $method = "GET", $headers = array(), $accessToken = null)
{
$parametersString = '';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $link);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if ($accessToken) {
$headers[] = 'Authorization: Bearer '.$accessToken;
}
if ($method === 'POST') {
curl_setopt($curl, CURLOPT_POST, count($parameters));
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($parameters));
}
if ($headers) {
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
$out = curl_exec($curl);
$info = curl_getinfo($curl);
curl_close($curl);
return $out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment