Май 4, 2010

View Comments

PHP :: Последние посты из Твиттера

Приведенный ниже код позволяет отобразить 5 последних записей из Twitter на вашем WordPress блоге с помощью интеграции RSS-ленты.

Для вывода ваших статусов, 82862879 необходимо заменить на ваш Twitter ID.

items) && 0 != count($rss->items) ) {
?>
<ul>
items = array_slice($rss-&gt;items, 0, 5);
foreach ($rss-&gt;items as $item ) {
?&gt;
	<li>
<a href="&lt;?php echo wp_filter_kses($item[">'&gt;
 
</a></li>
</ul>

Источник

Далее
Апр 30, 2010

View Comments

PHP :: Количество фолловеров в твиттере

Раньше количество твиттер-фолловеров на блоге показывалось небольшой кнопкой какого-то стороннего сервиса. Оказалось что посчитать их вполне можно вот таким нехитрым -скриптом.

<?php
$xml = file_get_contents('http://twitter.com/users/show.xml?screen_name=DJ_Petrovich');
if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
 $tw['count'] = $match[1];
}
echo $tw['count'];
?>

Далее
Апр 25, 2010

View Comments

PHP :: Автофолловинг в Твиттер

Периодически натыкаюсь на всякие полезные куски скриптов, поэтому буду записывать их в свой блог в отдельную рубрику чтобы не потерять. Вы же не против?

// Twitter Auto-follow Script by Dave Stevens - http://davestevens.co.uk
$user = "";
$pass = "";
$term = "";
$userApiUrl = "http://twitter.com/statuses/friends.json";
$ch = curl_init($userApiUrl);
curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$apiresponse = curl_exec($ch);
curl_close($ch);
$followed = array();
if ($apiresponse) {
	$json = json_decode($apiresponse);
	if ($json != null) {
		foreach ($json as $u) {
			$followed[] = $u-&gt;name;
		}
	}
}
$userApiUrl = "http://search.twitter.com/search.json?q=" . $term . "&amp;rpp=100";
$ch = curl_init($userApiUrl);
curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$apiresponse = curl_exec($ch);
curl_close($ch);
if ($apiresponse) {
	$results = json_decode($apiresponse);
	$count = 20;
	if ($results != null) {
		$resultsArr = $results-&gt;results;
		if (is_array($resultsArr)) {
			foreach ($resultsArr as $result) {
				$from_user = $result-&gt;from_user;
				if (!in_array($from_user,$followed)) {
					$ch = curl_init("http://twitter.com/friendships/create/" . $from_user . ".json");
					curl_setopt($ch, CURLOPT_USERPWD, $user.":".$pass);
					curl_setopt($ch, CURLOPT_POST, 1);
					curl_setopt($ch, CURLOPT_POSTFIELDS,"follow=true");
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
					$apiresponse = curl_exec($ch);
 
					if ($apiresponse) {
						$response = json_decode($apiresponse);
						if ($response != null) {
							if (property_exists($response,"following")) {
								if ($response-&gt;following === true) {
									echo "Now following " . $response-&gt;screen_name . "\n";
								} else {
									echo "Couldn't follow " . $response-&gt;screen_name . "\n";
								}
							} else {
								echo "Follow limit exceeded, skipped " . $from_user . "\n";
							}
						}
					}
					curl_close($ch);
				} else {
					echo "Already following " . $from_user . "\n";
				}
			}
		}
	}
}

Далее