twitter使用代理_使用PHP测试Twitter友谊

本文介绍了一种使用PHP测试Twitter上两个用户是否互相关注的方法,通过API调用和正则表达式解析返回的XML数据来实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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很有趣,不是吗?

翻译自: https://davidwalsh.name/twitter-friendships

twitter使用代理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值