Some fixups

This commit is contained in:
Zach Copley 2010-10-07 19:40:31 -07:00
parent be1668a1bd
commit 3e0a1e3b88

View File

@ -22,16 +22,16 @@ define('INSTALLDIR', realpath(dirname(__FILE__) . '/../..'));
require_once INSTALLDIR . '/extlib/OAuth.php'; require_once INSTALLDIR . '/extlib/OAuth.php';
$shortoptions = 'o:s:u:'; $shortoptions = 't:s:u:';
$longoptions = array('oauth_token=', 'token_secret=', 'update='); $longoptions = array('oauth_token=', 'token_secret=', 'update=');
$helptext = <<<END_OF_VERIFY_HELP $helptext = <<<END_OF_VERIFY_HELP
statusupdate.php [options] oauth_post_notice.php [options]
Update your status using OAuth Update your status via OAuth
-o --oauth_token access token -t --oauth_token access token
-s --token_secret access token secret -s --oauth_token_secret access token secret
-u --update status update -u --update status update
END_OF_VERIFY_HELP; END_OF_VERIFY_HELP;
@ -42,12 +42,12 @@ $update = null;
require_once INSTALLDIR . '/scripts/commandline.inc'; require_once INSTALLDIR . '/scripts/commandline.inc';
if (have_option('o', 'oauth_token')) { if (have_option('t', 'oauth_token')) {
$token = get_option_value('oauth_token'); $token = get_option_value('t', 'oauth_token');
} }
if (have_option('s', 'token_secret')) { if (have_option('s', 'oauth_token_secret')) {
$token_secret = get_option_value('s', 'token_secret'); $token_secret = get_option_value('s', 'oauth_token_secret');
} }
if (have_option('u', 'update')) { if (have_option('u', 'update')) {
@ -69,47 +69,56 @@ if (empty($update)) {
exit(1); exit(1);
} }
$ini = parse_ini_file("oauth.ini"); $ini = parse_ini_file("oauth.ini");
$consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
$test_consumer = new OAuthConsumer($ini['consumer_key'], $ini['consumer_secret']);
$endpoint = $ini['apiroot'] . '/statuses/update.xml'; $endpoint = $ini['apiroot'] . '/statuses/update.xml';
print "$endpoint\n"; $atok = new OAuthToken($token, $token_secret);
$at = new OAuthToken($token, $token_secret);
$parsed = parse_url($endpoint); $parsed = parse_url($endpoint);
$params = array();
parse_str($parsed['query'], $params); parse_str($parsed['query'], $params);
$params['status'] = $update; $params['status'] = $update;
$hmac_method = new OAuthSignatureMethod_HMAC_SHA1(); $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
$req_req = OAuthRequest::from_consumer_and_token($test_consumer, $at, 'POST', $endpoint, $params); try {
$req_req->sign_request($hmac_method, $test_consumer, $at);
$r = httpRequest($req_req->to_url()); $oauthReq = OAuthRequest::from_consumer_and_token(
$consumer,
$atok,
'POST',
$endpoint,
$params
);
$body = $r->getBody(); $oauthReq->sign_request($hmac_method, $consumer, $atok);
print "$body\n"; $httpReq = httpRequest($endpoint, $oauthReq->to_postdata());
//print $req_req->to_url() . "\n\n"; print $httpReq->getBody();
function httpRequest($url) } catch (Exception $e) {
print "Error! . $e->getMessage() . 'HTTP reponse body: " . $httpReq->getBody();
exit(1);
}
function httpRequest($endpoint, $poststr)
{ {
$request = HTTPClient::start(); $request = HTTPClient::start();
$request->setConfig(array( $request->setConfig(
'follow_redirects' => true, array(
'connect_timeout' => 120, 'follow_redirects' => true,
'timeout' => 120, 'connect_timeout' => 120,
'ssl_verify_peer' => false, 'timeout' => 120,
'ssl_verify_host' => false 'ssl_verify_peer' => false,
)); 'ssl_verify_host' => false
)
);
return $request->post($url); // Turn signed request query string back into an array
parse_str($poststr, $postdata);
return $request->post($endpoint, null, $postdata);
} }