twitter使用代理
Another awesome functionality provided by Twitter is the ability to test friendships between two people. I mean testing if two people follow each other, not if one spams the world with crap tweets. Just as with every other Twitter API call, executing this test is easy with PHP.
Twitter提供的另一个很棒的功能是测试两个人之间的友谊的能力。 我的意思是测试两个人是否彼此跟随,而不是测试一个人是否在用垃圾邮件向世界发送垃圾邮件。 与其他所有Twitter API调用一样,使用PHP轻松执行此测试。
PHP (The PHP)
/* persons to test */
$person1 = 'davidwalshblog';
$person2 = 'mootools';
/* send request to twitter */
$url = 'http://twitter.com/friendships/exists';
$format = 'xml';
/* check */
$persons12 = make_request($url.'.'.$format.'?user_a='.$person1.'&user_b='.$person2);
$result = get_match('/<friends>(.*)<\/friends>/isU',$persons12);
echo '<pre>Am I friends with @mootools?'.$result.'</pre>'; // returns "true" or "false"
/* makes the request */
function make_request($url) {
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/* gets the match */
function get_match($regex,$content)
{
preg_match($regex,$content,$matches);
return $matches[1];
}
That's it. I didn't use SimpleXML in my example because of the small size of the return XML. Too much extra overhead. Here's the XML sample response:
而已。 由于返回XML的大小较小,因此我在示例中未使用SimpleXML。 过多的额外开销。 这是XML示例响应:
<friends>true</friends>
The Twitter API is fun, isn't it?
Twitter API很有趣,不是吗?
twitter使用代理