【发布时间】:2014-05-22 15:39:54
【问题描述】:
我在 dev.twitter.com 创建了一个应用程序,我的应用程序正在这里以 JSON 格式从我的 Twitter 发布数据:http://projweb.hj.se/~hada1192/twitter/tweets_json.php
我对 Twitter API、JSON 和 PHP 很陌生,所以我现在的问题是:如何选择我的推文(我只想要文本,例如“我的第一条推文”、“我的第二条推文,推特很有趣", "不能告诉你过山车有多享受") 在一个 PHP 数组中?
这是我的代码:
<?php
require 'tmhOAuth.php'; // Get it from: https://github.com/themattharris/tmhOAuth
// Use the data from http://dev.twitter.com/apps to fill out this info
// notice the slight name difference in the last two items)
$connection = new tmhOAuth(array(
'consumer_key' => 'xxx',
'consumer_secret' => 'zz',
'user_token' => '547733151-yyy', //access token
'user_secret' => 'ooo' //access token secret
));
// set up parameters to pass
$parameters = array();
if ($_GET['count']) {
$parameters['count'] = strip_tags($_GET['count']);
}
if ($_GET['screen_name']) {
$parameters['screen_name'] = strip_tags($_GET['screen_name']);
}
if ($_GET['twitter_path']) { $twitter_path = $_GET['twitter_path']; } else {
$twitter_path = '1.1/statuses/user_timeline.json';
}
$http_code = $connection->request('GET', $connection->url($twitter_path), $parameters );
if ($http_code === 200) // if everything's good
{
$response = strip_tags($connection->response['response']);
if ($_GET['callback']) // if we ask for a jsonp callback function
{
echo $_GET['callback'],'(', $response,');';
}
else
{
echo $response;
}
}
else
{
echo "Error ID: ",$http_code, "<br>\n";
echo "Error: ",$connection->response['error'], "<br>\n";
}
?>
【问题讨论】:
标签: php json twitter twitter-oauth