正如你们中的一些人可能知道的,Twitter已经改变了他们的API。
因此,我的一些插件/代码停止工作。我试着自己修复它们,但失败了。我尝试在谷歌上搜索新的API URL,并在这里进行了搜索。我试图插入中提供的URLthis post, 但一旦申请,我只收到一条错误消息。
我需要用新的API更新以下两个代码,但不知道如何更新!
推特关注者计数片段:
function rarst_twitter_user( $username, $field, $display = false ) {
$interval = 3600;
$cache = get_option(\'rarst_twitter_user\');
$url = \'http://api.twitter.com/1/users/show.json?screen_name=\'.urlencode($username);
if ( false == $cache )
$cache = array();
// if first time request add placeholder and force update
if ( !isset( $cache[$username][$field] ) ) {
$cache[$username][$field] = NULL;
$cache[$username][\'lastcheck\'] = 0;
}
// if outdated
if( $cache[$username][\'lastcheck\'] < (time()-$interval) ) {
// holds decoded JSON data in memory
static $memorycache;
if ( isset($memorycache[$username]) ) {
$data = $memorycache[$username];
}
else {
$result = wp_remote_retrieve_body(wp_remote_request($url));
$data = json_decode( $result );
if ( is_object($data) )
$memorycache[$username] = $data;
}
if ( is_object($data) ) {
// update all fields, known to be requested
foreach ($cache[$username] as $key => $value)
if( isset($data->$key) )
$cache[$username][$key] = $data->$key;
$cache[$username][\'lastcheck\'] = time();
}
else {
$cache[$username][\'lastcheck\'] = time()+60;
}
update_option( \'rarst_twitter_user\', $cache );
}
if ( false != $display )
echo $cache[$username][$field];
return $cache[$username][$field];
显示最新推文片段:
function recentTweets($username, $number){
include_once(ABSPATH.WPINC.\'/rss.php\');
$tweet = fetch_feed("http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=" . $number );
if (!is_wp_error( $tweet ) ) :
$maxitems = $tweet->get_item_quantity($number);
$rss_items = $tweet->get_items(0, $maxitems);
endif;
if ($maxitems == 0) echo \'<li>No Tweets.</li>\';
else foreach ( $rss_items as $item ) {
$content = html_entity_decode($item->get_content());
$link = html_entity_decode($item->get_permalink());
$date = $item->get_date(\'U\'); // retrives the tweets date and time in Unix Epoch terms
$blogtime = current_time(\'U\'); // retrives the current browser client date and time in Unix Epoch terms
$dago = human_time_diff($date, $blogtime) . \' ago\'; // calculates and outputs the time past in human readable format
echo "<li>$content •<a href=\'$link\'>$dago</a></li>";
}
}
提前非常感谢您。这是
my blog 供参考。