次のコードを使用して、TwitterのAPIで検索を実行しています。
$.post('lib/themattharris-tmhOAuth-38bd48b/search.php',
{q:'@something',
pages:'1'}
)
.done(function(xhr) {
try
{
var tweets = $.parseJSON(xhr.responseText);
}
catch (e)
{
showError('Error : '+e.message);
return;
}
if (tweets === null)
{
showError('Error : no tweets found');
return;
}
$('#timeline').text(tweets.results[0].text);
})
.fail(function(xhr, textStatus, errorThrown) {
showError('Error : ' + $.parseJSON(xhr.responseText).error);
})
.always(function() {
$('#load').removeAttr('disabled');
});
しかし、「ツイート」は常にnull
です。Mysearch.php
が検索を実行し、結果をエコーします。jsonlintで返されたJSONを確認しましたが、エラーは見つかりませんでした。
手がかりはありますか?
ここで編集search.php
:
require_once 'tmhOAuth.php';
require_once 'tmhUtilities.php';
require_once 'secrets.php';
session_start();
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => $consumerKey,
'consumer_secret' => $consumerSecret,
'user_token' => $_SESSION['access_token']['oauth_token'],
'user_secret' => $_SESSION['access_token']['oauth_token_secret']
));
$p['q'] = $_POST['q'];
$p['pages'] = 1;
$p['include_entities'] = 'true';
$pages = intval($p['pages']);
$results = array();
$code = $tmhOAuth->request(
'GET',
'http://search.twitter.com/search.json',
$p,
false
);
if ($code !== 200) {
header("HTTP/1.1 500 Internal Server Error");
echo $tmhOAuth->response['response'];
return;
}
else
{
echo $tmhOAuth->response['response'];
}