mirror of
https://github.com/thewesker/greptweet.git
synced 2025-12-21 12:41:04 -05:00
1.1 work has begun
This commit is contained in:
59
oauth.php
Normal file
59
oauth.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
function buildBaseString($baseURI, $method, $params) {
|
||||
$r = array();
|
||||
ksort($params);
|
||||
foreach($params as $key=>$value){
|
||||
$r[] = "$key=" . rawurlencode($value);
|
||||
}
|
||||
return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r));
|
||||
}
|
||||
|
||||
function buildAuthorizationHeader($oauth) {
|
||||
$r = 'Authorization: OAuth ';
|
||||
$values = array();
|
||||
foreach($oauth as $key=>$value)
|
||||
$values[] = "$key=\"" . rawurlencode($value) . "\"";
|
||||
$r .= implode(', ', $values);
|
||||
return $r;
|
||||
}
|
||||
|
||||
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
|
||||
|
||||
// Get $oauth_access_token, $oauth_access_token_secret, $consumer_key, $consumer_secret
|
||||
include("secret.php");
|
||||
|
||||
$oauth = array( 'oauth_consumer_key' => $consumer_key,
|
||||
'oauth_nonce' => time(),
|
||||
'oauth_signature_method' => 'HMAC-SHA1',
|
||||
'oauth_token' => $oauth_access_token,
|
||||
'oauth_timestamp' => time(),
|
||||
'screen_name' => 'kaihendry',
|
||||
'count' => 200,
|
||||
'max_id' => 292551485714227200,
|
||||
'oauth_version' => '1.0');
|
||||
|
||||
$base_info = buildBaseString($url, 'GET', $oauth);
|
||||
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
|
||||
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
|
||||
$oauth['oauth_signature'] = $oauth_signature;
|
||||
|
||||
// Make Requests
|
||||
$header = array(buildAuthorizationHeader($oauth), 'Expect:');
|
||||
$options = array( CURLOPT_HTTPHEADER => $header,
|
||||
//CURLOPT_POSTFIELDS => $postfields,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_URL => $url . '?screen_name=kaihendry&count=200&max_id=292551485714227200',
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false);
|
||||
|
||||
$feed = curl_init();
|
||||
curl_setopt_array($feed, $options);
|
||||
$json = curl_exec($feed);
|
||||
curl_close($feed);
|
||||
|
||||
echo $json;
|
||||
// $twitter_data = json_decode($json);
|
||||
// print_r ($twitter_data);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user