Php example to read all tweets for a specific user
2019-01-27
<?php
$client_id="xeqroM123123AKwcVcf";
$client_sec="lB9UvkQjsdaKq60h9KMldT31hYm123123ucBjWKl2";
$token = base64_encode($client_id.':'.$client_sec);
$data = array ('grant_type' => 'client_credentials');
$data = http_build_query($data);
$header = array(
'Authorization: Basic '.$token,
'Content-type: application/x-www-form-urlencoded;charset=UTF-8',
'Content-Length: ' . strlen($data)
);
function get($header, $data, $url){
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $data
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
//print_r($result);
curl_close($ch);
return json_decode($result);
}
function get2($url, $bearer){
$options = array(
CURLOPT_HTTPHEADER => array('Authorization: Bearer '.$bearer),
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);
}
$result=get($header, $data, 'https://api.twitter.com/oauth2/token');
$bearer=$result->access_token;
//var_dump($result);
echo $bearer."\n";
$result=get2('https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=KEFAudio', $bearer);
var_dump($result);
exit;
?>