Skip to content

Instantly share code, notes, and snippets.

@jamiemtdwyer
Created January 19, 2018 22:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jamiemtdwyer/cbf483375aa635fcde4b04e2a8b645e8 to your computer and use it in GitHub Desktop.
Save jamiemtdwyer/cbf483375aa635fcde4b04e2a8b645e8 to your computer and use it in GitHub Desktop.
Exchange authorization code
// Set variables for our request
$query = array(
"client_id" => $api_key, // Your API key
"client_secret" => $shared_secret, // Your app credentials (secret key)
"code" => $params['code'] // Grab the access key from the URL
);
// Generate access token URL
$access_token_url = "https://" . $params['shop'] . "/admin/oauth/access_token";
// Configure curl client and execute request
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $access_token_url);
curl_setopt($ch, CURLOPT_POST, count($query));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($query));
$result = curl_exec($ch);
curl_close($ch);
// Store the access token
$result = json_decode($result, true);
$access_token = $result['access_token'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment