Skip to content

Commit 506ae0b

Browse files
committed
syntax errors from jonhurlock#2 and output buffering fix
output buffering is not required, use the return transfer flag instead also merged changes from jonhurlock#2 while I was at it to avoid merge conflicts
1 parent e2dd9d8 commit 506ae0b

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

Oauth.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,17 @@ function get_bearer_token(){
4141
curl_setopt($ch, CURLOPT_URL,$url); // set url to send to
4242
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // set custom headers
4343
curl_setopt($ch, CURLOPT_POST, 1); // send as post
44+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return output
4445
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials"); // post body/fields to be sent
4546
$header = curl_setopt($ch, CURLOPT_HEADER, 1); // send custom headers
4647
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
47-
ob_start(); // start ouput buffering
48-
curl_exec ($ch); // execute the curl
49-
$retrievedhtml = ob_get_contents(); // grab the retreived html
50-
ob_end_clean(); //End buffering and clean output
48+
$retrievedhtml = curl_exec ($ch); // execute the curl
5149
curl_close($ch); // close the curl
5250
$output = explode("\n", $retrievedhtml);
5351
$bearer_token = '';
5452
foreach($output as $line)
5553
{
56-
if($pos === false)
54+
if($line === false)
5755
{
5856
// there was no bearer token
5957
}else{
@@ -90,13 +88,11 @@ function invalidate_bearer_token($bearer_token){
9088
curl_setopt($ch, CURLOPT_URL,$url); // set url to send to
9189
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // set custom headers
9290
curl_setopt($ch, CURLOPT_POST, 1); // send as post
91+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return output
9392
curl_setopt($ch, CURLOPT_POSTFIELDS, "access_token=".$bearer_token.""); // post body/fields to be sent
9493
$header = curl_setopt($ch, CURLOPT_HEADER, 1); // send custom headers
9594
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
96-
ob_start(); // start ouput buffering
97-
curl_exec ($ch); // execute the curl
98-
$retrievedhtml = ob_get_contents(); // grab the retreived html
99-
ob_end_clean(); //End buffering and clean output
95+
$retrievedhtml = curl_exec ($ch); // execute the curl
10096
curl_close($ch); // close the curl
10197
return $retrievedhtml;
10298
}
@@ -106,14 +102,14 @@ function invalidate_bearer_token($bearer_token){
106102
* Basic Search of the Search API
107103
* Based on https://dev.twitter.com/docs/api/1/get/search
108104
*/
109-
function search_for_a_term($bearer_token, $query, $result_type='mixed' $rpp='15'){
105+
function search_for_a_term($bearer_token, $query, $result_type='mixed', $rpp='15'){
110106
$url = "https://api.twitter.com/1.1/search/tweets.json"; // base url
111107
$q = $query; // query term
112108

113109
$formed_url ='?q='.$q; // fully formed url
114110
if($result_type!='mixed'){$formed_url = $formed_url.'&result_type='.$result_type;} // result type - mixed(default), recent, popular
115111
if($rpp!='15'){$formed_url = $formed_url.'&rpp='.$rpp;} // results per page - defaulted to 15
116-
$formed_url = $formed_url.'&include_entities=true' // makes sure the entities are included, note @mentions are not included see documentation
112+
$formed_url = $formed_url.'&include_entities=true'; // makes sure the entities are included, note @mentions are not included see documentation
117113
$headers = array(
118114
"GET /1.1/search/tweets.json".$formed_url." HTTP/1.1",
119115
"Host: api.twitter.com",
@@ -123,10 +119,8 @@ function search_for_a_term($bearer_token, $query, $result_type='mixed' $rpp='15'
123119
$ch = curl_init(); // setup a curl
124120
curl_setopt($ch, CURLOPT_URL,$url.$formed_url); // set url to send to
125121
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // set custom headers
126-
ob_start(); // start ouput buffering
127-
$output = curl_exec ($ch); // execute the curl
128-
$retrievedhtml = ob_get_contents(); // grab the retreived html
129-
ob_end_clean(); //End buffering and clean output
122+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return output
123+
$retrievedhtml = curl_exec ($ch); // execute the curl
130124
curl_close($ch); // close the curl
131125
return $retrievedhtml;
132126
}
@@ -135,4 +129,4 @@ function search_for_a_term($bearer_token, $query, $result_type='mixed' $rpp='15'
135129
$bearer_token = get_bearer_token(); // get the bearer token
136130
print search_for_a_term($bearer_token, "test"); // search for the work 'test'
137131
invalidate_bearer_token($bearer_token); // invalidate the token
138-
?>
132+
?>

0 commit comments

Comments
 (0)