Last active
May 11, 2020 06:18
-
-
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 :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
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
hi, thanks for your post, i have only CONSUMER_SECRET and CONSUMER_KEY... what is TOKEN and TOKEN_SECRET...