我正在开发一个php网站。在这里我想在我的网站上显示twitter更新。我有一个推特帐户。但我不知道如何显示twitter更新。有人知道吗? 请帮我在我的网站上显示twitter updtaes
在此先感谢
我正在开发一个php网站。在这里我想在我的网站上显示twitter更新。我有一个推特帐户。但我不知道如何显示twitter更新。有人知道吗? 请帮我在我的网站上显示twitter updtaes
在此先感谢
也许这可以帮助。 http://twitter.com/about/resources/widgets
问候!
很久以前,我已经为wordpress做过这个工作,但我想,如果你想要一些个人解决方案(在说话的时候),你可以使用它。不过最好还是看看他们提供的例子https://twitter.com/about/resources/widgets/widget_list或https://dev.twitter.com/docs/api
/**
* Function for displaying twitter statuses
*
* @param string $userName
* @param int $howMany
*/
function display_tweets($userName, $howMany = 3)
{
$statuses = json_decode(file_get_contents("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name={$userName}&count={$howMany}"));
echo '<div style="width: 300px;"><ol style="list-style: none; margin: 0; padding: 0;">';
foreach ($statuses as $Status)
{
$statusText = $Status->text;
if (! empty($Status->entities->urls))
{
foreach ($Status->entities->urls as $Url)
{
if ('' !== trim($Url->expanded_url))
{
$statusText = str_replace($Url->url, "<a href=\"{$Url->expanded_url}\" target=\"_blank\" rel=\"nofollow\">{$Url->display_url}</a>", $statusText);
}
}
}
$from = '';
if (null !== $Status->place)
{
$from = $Status->place->full_name;
}
display_tweet($statusText, $userName, $Status->id, $Status->created_at, $from);
}
echo '</ol></div>';
}
/**
* Function for displaying status in url (user-readable-language :))
*
* @param string $statusText
* @param string $userName
* @param int $statusId
* @param string $createdAt
* @param string $from
*/
function display_tweet($statusText, $userName, $statusId, $createdAt, $from = '')
{
echo '<li style="border-bottom: solid 1px #CCC; padding: 5px 0px; overflow: hidden;">';
echo '<span class="status-body">';
echo '<span class="status-content">';
echo '<span class="entry-content">';
echo $statusText;
echo '</span>';
echo '</span>';
echo '<span class="meta entry-meta" style="display: block; color: #999; font-size: x-small;">';
echo "<a class=\"entry-date\" rel=\"nofollow\" target=\"_blank\" href=\"http://twitter.com/{$userName}/status/{$statusId}\">";
echo '<span class="published timestamp">' . date('g:i A M jS, Y', strtotime($createdAt)) . '</span>';
echo "</a>";
if ('' !== trim($from))
{
echo ' from ';
echo "<a class=\"geocoded_google_link\" rel=\"nofollow\" target=\"_blank\" href=\"http://maps.google.com/maps?q={$from}\">{$from}</a>";
}
echo '</span>';
echo '</span>';
echo '</li>';
}
http://twitter.com/about/resources/widgets – JJJ 2012-03-29 06:47:09
http://css-tricks.com/snippets/php/get-latest- Twitter的状态/ – Andy 2012-03-29 07:09:22