Created
May 24, 2013 05:28
-
-
Save dmadisetti/5641438 to your computer and use it in GitHub Desktop.
Minimalist Twitter API status post from wordpress.
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
function tweet($status){ | |
$oauth_consumer_key = "key"; | |
$oauth_token = "token"; | |
$oauth_signature_method = "HMAC-SHA1"; | |
$oauth_timestamp = time(); | |
$oauth_nonce = hash("md5","Random" . $oauth_timestamp . "32 bit string"); | |
$baseurl = "https://api.twitter.com/1.1/statuses/update.json"; | |
$url= ''; | |
$url.= "?oauth_consumer_key=".rawurlencode($oauth_consumer_key); | |
$url.= "&oauth_nonce=" . rawurlencode($oauth_nonce); | |
$url.= "&oauth_signature_method=".rawurlencode($oauth_signature_method); | |
$url.= "&oauth_timestamp=" . rawurlencode($oauth_timestamp); | |
$url.= "&oauth_token=" . rawurlencode($oauth_token); | |
$url.= "&oauth_version=" . rawurlencode("1.0"); | |
$url.= "&status=" . rawurlencode(substr($status,0,140)); | |
$oauth_signature = hash_hmac('sha1', 'POST&'.rawurlencode($baseurl).'&'.rawurlencode(str_replace('?', '', $url)), 'consumersecret&applicationsecret', TRUE); | |
$url.= "&oauth_signature=" . rawurlencode(base64_encode($oauth_signature)); | |
$response = wp_remote_post($baseurl.$url); | |
} | |
tweet('Cool story bro. Fork it again.'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment