Skip to content

Commit 364290d

Browse files
committed
Merge pull request jonhurlock#3 from soulseekah/return-output-curl
syntax errors from jonhurlock#2 and output buffering fix
2 parents 1f03dc2 + 506ae0b commit 364290d

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

Oauth.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@ 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 = '';
@@ -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
}
@@ -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)