#!/usr/bin/env php . */ define('INSTALLDIR', realpath(__DIR__ . '/../..')); require_once INSTALLDIR . '/extlib/OAuth.php'; $ini = parse_ini_file('oauth.ini'); // Check to make sure we have everything we need from the ini file foreach (['consumer_key', 'consumer_secret', 'apiroot', 'access_token_url'] as $inikey) { if (empty($ini[$inikey])) { echo "You forgot to specify a {$inikey} in your oauth.ini file.\n"; exit(1); } } $consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']); $endpoint = $ini['apiroot'] . $ini['access_token_url']; $shortoptions = 't:s:v:'; $longoptions = ['oauth_token=', 'oauth_token_secret=', 'oauth_verifier=']; $helptext = <<sign_request($hmac_method, $consumer, $rtok); $httpReq = httpRequest($endpoint, $oauthReq->to_postdata()); $body = $httpReq->getBody(); } catch (Exception $e) { // oh noez echo $e->getMessage(); echo "\nOAuth Request:\n"; var_dump($oauthReq); exit(1); } $tokenStuff = []; parse_str($body, $tokenStuff); if (empty($tokenStuff['oauth_token']) || empty($tokenStuff['oauth_token_secret'])) { echo "Error! HTTP response body: {$body}\n"; exit(1); } echo "Access Token\n"; echo ' - oauth_token = ' . $tokenStuff['oauth_token'] . "\n"; echo ' - oauth_token_secret = ' . $tokenStuff['oauth_token_secret'] . "\n"; function httpRequest($endpoint, $poststr) { $request = HTTPClient::start(); $request->setConfig( [ 'follow_redirects' => true, 'connect_timeout' => 120, 'timeout' => 120, 'ssl_verify_peer' => false, 'ssl_verify_host' => false, ] ); parse_str($poststr, $postdata); return $request->post($endpoint, null, $postdata); }