Skip to content

Instantly share code, notes, and snippets.

@jmauerhan
Last active May 11, 2020 06:18
Show Gist options
  • Save jmauerhan/990f39ef082a7e220001 to your computer and use it in GitHub Desktop.
Save jmauerhan/990f39ef082a7e220001 to your computer and use it in GitHub Desktop.
This is an example of using PHP's OAuth extension (available via PECL) to make a request to an API that requires a signature instead of access and refresh tokens. I was unable to find an example of how to do this, so hopefully if anyone else has to they will find this :)
<?php
define("CONSUMER_SECRET", "secret");
define("CONSUMER_KEY", "key");
define("TOKEN", "token");
define("TOKEN_SECRET", "token secret");
define("URL_API", "https://api.***");
$method = "GET";
$nonce = md5(time());
$url = URL_API . '/items/';
$oauth = new OAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_SIG_METHOD_HMACSHA1);
$oauth->disableSSLChecks();
$oauth->enableDebug();
$oauth->setToken(TOKEN, TOKEN_SECRET);
$oauth->setNonce($nonce);
$oauth->generateSignature($method, $url);
$oauth->fetch($url);
$response = $oauth->getLastResponse();
$responseData = json_decode($response);
var_dump($responseData);
@juangonzaq
Copy link

juangonzaq commented May 19, 2017

hi, thanks for your post, i have only CONSUMER_SECRET and CONSUMER_KEY... what is TOKEN and TOKEN_SECRET...

@taggart-comet
Copy link

hi, thanks for your post, i have only CONSUMER_SECRET and CONSUMER_KEY... what is TOKEN and TOKEN_SECRET...

if you don't have just don't set it = )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment