php http apiwiki twitter com Twitter-Search-API-M ethod 3A-search requ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* http://apiwiki.twitter.com/Twitter-Search-API-Method%3A-search
*
*/
require_once dirname(__FILE__) . '/config.php';
require_once dirname(__FILE__) . '/Zend/Json.php';
$mysqlConnection = mysql_connect ($config['db']['host'], $config['db']['username'], $config['db']['password']);
mysql_select_db($config['db']['database'], $mysqlConnection);
$r = mysql_fetch_array(mysql_query("SELECT twiID FROM quotes ORDER BY twiID DESC LIMIT 1"));
/**
* http://search.twitter.com/search.json?q=twitter&since_id=1520639490
*
*/
$oCurl = curl_init("http://search.twitter.com/search.json?q=%23qmd&since_id=" . $r[0]);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($oCurl);
$content = Zend_Json::Decode($content);
$content = $content['results'];
/**
* echo "<pre>";
* print_r($content);
* echo "</pre>";
*/
$count = count($content);
if ($count < 1) die();
//
$toQ = 'INSERT INTO quotes (twiID, author, quote, time) VALUES';
for ($i = 0; $i < $count; $i++) {
$toQ .= " ('" . $content[$i]['id'] . "', '" . $content[$i]['from_user'] . "', '" . $content[$i]['text'] . "', '" . $content[$i]['created_at'] . "')";
if ($i < $count - 1) $toQ .= ",";
}
mysql_query($toQ);
/**
* Log info
*/
$file = fopen('log/' . date("d.d.Y G-i"), "w");
fclose($file);