@@ -41,19 +41,17 @@ function get_bearer_token(){
41
41
curl_setopt ($ ch , CURLOPT_URL ,$ url ); // set url to send to
42
42
curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ headers ); // set custom headers
43
43
curl_setopt ($ ch , CURLOPT_POST , 1 ); // send as post
44
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true ); // return output
44
45
curl_setopt ($ ch , CURLOPT_POSTFIELDS , "grant_type=client_credentials " ); // post body/fields to be sent
45
46
$ header = curl_setopt ($ ch , CURLOPT_HEADER , 1 ); // send custom headers
46
47
$ 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
51
49
curl_close ($ ch ); // close the curl
52
50
$ output = explode ("\n" , $ retrievedhtml );
53
51
$ bearer_token = '' ;
54
52
foreach ($ output as $ line )
55
53
{
56
- if ($ pos === false )
54
+ if ($ line === false )
57
55
{
58
56
// there was no bearer token
59
57
}else {
@@ -90,13 +88,11 @@ function invalidate_bearer_token($bearer_token){
90
88
curl_setopt ($ ch , CURLOPT_URL ,$ url ); // set url to send to
91
89
curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ headers ); // set custom headers
92
90
curl_setopt ($ ch , CURLOPT_POST , 1 ); // send as post
91
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true ); // return output
93
92
curl_setopt ($ ch , CURLOPT_POSTFIELDS , "access_token= " .$ bearer_token ."" ); // post body/fields to be sent
94
93
$ header = curl_setopt ($ ch , CURLOPT_HEADER , 1 ); // send custom headers
95
94
$ 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
100
96
curl_close ($ ch ); // close the curl
101
97
return $ retrievedhtml ;
102
98
}
@@ -106,14 +102,14 @@ function invalidate_bearer_token($bearer_token){
106
102
* Basic Search of the Search API
107
103
* Based on https://dev.twitter.com/docs/api/1/get/search
108
104
*/
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 ' ){
110
106
$ url = "https://api.twitter.com/1.1/search/tweets.json " ; // base url
111
107
$ q = $ query ; // query term
112
108
113
109
$ formed_url ='?q= ' .$ q ; // fully formed url
114
110
if ($ result_type !='mixed ' ){$ formed_url = $ formed_url .'&result_type= ' .$ result_type ;} // result type - mixed(default), recent, popular
115
111
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
117
113
$ headers = array (
118
114
"GET /1.1/search/tweets.json " .$ formed_url ." HTTP/1.1 " ,
119
115
"Host: api.twitter.com " ,
@@ -123,10 +119,8 @@ function search_for_a_term($bearer_token, $query, $result_type='mixed' $rpp='15'
123
119
$ ch = curl_init (); // setup a curl
124
120
curl_setopt ($ ch , CURLOPT_URL ,$ url .$ formed_url ); // set url to send to
125
121
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
130
124
curl_close ($ ch ); // close the curl
131
125
return $ retrievedhtml ;
132
126
}
@@ -135,4 +129,4 @@ function search_for_a_term($bearer_token, $query, $result_type='mixed' $rpp='15'
135
129
$ bearer_token = get_bearer_token (); // get the bearer token
136
130
print search_for_a_term ($ bearer_token , "test " ); // search for the work 'test'
137
131
invalidate_bearer_token ($ bearer_token ); // invalidate the token
138
- ?>
132
+ ?>
0 commit comments