我正在使用https://github.com/J7mbo/twitter-api-php作为oAuth等的库。
我现在只是在玩,但是,当我尝试从twitter api输出例如数组文本时,它会在最后显示奇怪的字符。我不确定这是否有意作为来自Twitter的eol,但它让我发疯,在输出结束时显示以下字符“5?%?0”
<?php
ini_set('display_errors', 1);
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "mytokensorkeys",
'oauth_access_token_secret' => "mytokensorkeys",
'consumer_key' => "mytokensorkeys",
'consumer_secret' => "mytokensorkeys"
);
/*
$url = 'https://api.twitter.com/1.1/blocks/create.json';
$requestMethod = 'POST';
$postfields = array(
'screen_name' => '',
'skip_status' => '1'
);
$twitter = new TwitterAPIExchange($settings);
echo $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();*/
/** Perform a GET request and echo the response **/
/** Note: Set the GET field BEFORE calling buildOauth(); **/
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=#smedigitalforum';
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
$response = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),true);
?>
<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta Content-type: application/json; charset=ISO-8859-1 />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title></title>
<link rel="stylesheet" href="css/foundation.css" />
<link rel="stylesheet" href="css/global.css" />
<script src="js/vendor/jquery.js"></script>
<script src="js/foundation.min.js"></script>
<script src="js/vendor/modernizr.js"></script>
</head>
<body>
<div class="row">
<?php
foreach($response as $key => $value){
foreach($value as $tweet){
print_r($tweet['text']);
}
}
?>
</div>
<script>
$(document).foundation();
</script>
</body>
</html>