web/search_tweets.php
changeset 1427 8b3d57a519eb
parent 919 e126d3e1e186
child 1474 53f0f4ed20c8
equal deleted inserted replaced
1426:15a1a28f609a 1427:8b3d57a519eb
     5 } else {
     5 } else {
     6 	header("Content-type: application/json");
     6 	header("Content-type: application/json");
     7 }
     7 }
     8 
     8 
     9 
     9 
    10 /**
       
    11  * include some common code (like we did in the 90s)
       
    12  * People still do this? ;)
       
    13  */
       
    14 include_once 'common.php';
    10 include_once 'common.php';
       
    11 use Abraham\TwitterOAuth\TwitterOAuth;
    15 
    12 
    16 /**
    13 /**
    17  * Check for a POSTed status message to send to Twitter
    14  * Check for a POSTed status message to send to Twitter
    18  */
    15  */
    19 if (!empty($_GET)
    16 if (!empty($_GET)
    22      * Easiest way to use OAuth now that we have an Access Token is to use
    19      * Easiest way to use OAuth now that we have an Access Token is to use
    23      * a preconfigured instance of Zend_Http_Client which automatically
    20      * a preconfigured instance of Zend_Http_Client which automatically
    24      * signs and encodes all our requests without additional work
    21      * signs and encodes all our requests without additional work
    25      */
    22      */
    26      
    23      
    27     if (isset($_GET['endpoint'])) {
    24     // if (isset($_GET['endpoint'])) {
    28     	$endpoint = $_GET['endpoint'];
    25     // 	$endpoint = $_GET['endpoint'];
    29 		unset($_GET['endpoint']);
    26 	// 	unset($_GET['endpoint']);
    30     } else {
    27     // } else {
    31     	$endpoint = "search/tweets";
    28     // 	$endpoint = "search/tweets";
    32     }
    29     // }
    33 
    30 
    34     $token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']);
    31     $token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']);
    35     $client = $token->getHttpClient($configuration);
    32     $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $token['oauth_token'], $token['oauth_token_secret']);
    36     $client->setUri("https://api.twitter.com/1.1/$endpoint.json");
       
    37     $client->setMethod(Zend_Http_Client::GET);
       
    38     $client->setParameterGet($_GET);
       
    39     $response = $client->request();
       
    40 
    33 
    41     echo $response->getBody();
    34     $statuses = $connection->get("search/tweets", $_GET);
       
    35     // $client = $token->getHttpClient($configuration);
       
    36     // $client->setUri("https://api.twitter.com/1.1/$endpoint.json");
       
    37     // $client->setMethod(Zend_Http_Client::GET);
       
    38     // $client->setParameterGet($_GET);
       
    39     // $response = $client->request();
       
    40 
       
    41     // echo $response->getBody();
       
    42     echo json_encode($statuses);
    42 
    43 
    43 } else {
    44 } else {
    44     /**
    45     /**
    45      * Mistaken request? Some malfeasant trying something?
    46      * Mistaken request? Some malfeasant trying something?
    46      */
    47      */