web/search_tweets.php
author ymh <ymh.work@gmail.com>
Sat, 22 Sep 2018 15:14:16 +0200
changeset 1471 c99372e45a90
parent 1427 8b3d57a519eb
child 1474 53f0f4ed20c8
permissions -rw-r--r--
Added tag V06.005 for changeset 4812c816aec1

<?php

if (isset ($_GET['callback'])) {
	header("Content-type: text/javascript");
} else {
	header("Content-type: application/json");
}


include_once 'common.php';
use Abraham\TwitterOAuth\TwitterOAuth;

/**
 * Check for a POSTed status message to send to Twitter
 */
if (!empty($_GET)
&& isset($_SESSION['TWITTER_ACCESS_TOKEN'])) {
    /**
     * Easiest way to use OAuth now that we have an Access Token is to use
     * a preconfigured instance of Zend_Http_Client which automatically
     * signs and encodes all our requests without additional work
     */
     
    // if (isset($_GET['endpoint'])) {
    // 	$endpoint = $_GET['endpoint'];
	// 	unset($_GET['endpoint']);
    // } else {
    // 	$endpoint = "search/tweets";
    // }

    $token = unserialize($_SESSION['TWITTER_ACCESS_TOKEN']);
    $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $token['oauth_token'], $token['oauth_token_secret']);

    $statuses = $connection->get("search/tweets", $_GET);
    // $client = $token->getHttpClient($configuration);
    // $client->setUri("https://api.twitter.com/1.1/$endpoint.json");
    // $client->setMethod(Zend_Http_Client::GET);
    // $client->setParameterGet($_GET);
    // $response = $client->request();

    // echo $response->getBody();
    echo json_encode($statuses);

} else {
    /**
     * Mistaken request? Some malfeasant trying something?
     */
    exit('Invalid tweet request. Oops. Sorry.');
}
?>