-1
<?php
require 'app_tokens2.php';
require 'tmhOAuth-master/tmhOAuth.php';
$query = htmlspecialchars($_GET['query']);
if (empty($query))
{
$query = "pitbull";
}
$connection = new tmhOAuth(array(
'consumer_key' => $consumer_key,
'consumer_secret' => $consumer_secret,
'user_token' => $user_token,
'user_secret' => $user_secret
));
// Get the timeline with the Twitter API
$http_code = $connection->request('GET',$connection->url('1.1/search/tweets'),
array('q' => $query,'count' => 4, 'lang' => 'en'));
// Request was successful
if ($http_code == 200)
{
// Extract the tweets from the API response
$response = json_decode($connection->response['response'],true);
$tweet_data = $response['statuses'];
// Accumulate tweets from results
$tweet_stream = '[';
foreach ($tweet_data as $tweet)
{
// Add this tweet's text to the results
$tweet_stream .= '{ "tweet":' . json_encode($tweet['text']) . ' },';
}
$tweet_stream = substr($tweet_stream, 0, -1);
$tweet_stream .= ']';
// Send the tweets back to the Ajax request
print $tweet_stream;
// Connect to Mongo and set DB and Collection
$mongo = new Mongo();
$db = $mongo->sample1;
$collection = $db->trial3;
// Convert JSON to a PHP array
$tweet_stream = json_decode($tweet_stream,true);
// Loop array and create seperate documents for each tweet
foreach ($tweet_stream as $item)
{
$collection->insert($item);
}
// fetch all tweets from the collection
$posts = $collection->find();
foreach ($posts as $post) {
// display the posts
//print $post;
print_r($post); //print_r prints a variable in a more human-readable form:
}
var_dump($collection->count()); //counts number of documents in a collection
}
// Handle errors from API request
else
{
if ($http_code == 429)
{
print 'Error: Twitter API rate limit reached';
}
else
{
print 'Error: Twitter was not able to process that request';
}
}
上述代碼工作正常。但問題是,如果我用post
方法是不working.Gives錯誤信息推特API的POST方法不起作用
'Error: Twitter was not able to process that request'
我想使用POST方法來獲得,當我試圖用POST方法錯誤更換地理標註tweets.But給出。
_「但是,當我嘗試用帖子替換」_ - 顯示我們_how_你試過了。 – CBroe