获取 Twitter 用户关注的用户 [英] Get users a Twitter user is following

查看:37
本文介绍了获取 Twitter 用户关注的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Twitter API 创建一个 Web 应用程序.但是,我希望能够获得特定用户关注的用户列表.我查看了文档,但无法找到如何执行此操作.

I am using the Twitter API to create a web application. However, I would like to be able to get a list of users that a specific user is following. I have looked at the documentation and I have not been able to find how to do this.

例如,我可能试图获取 baconman 关注的用户.如何使用 Twitter API 执行此操作?

For example, I might be trying to get the users that baconman is following. How can I do this using the Twitter API?

推荐答案

<?php 
     $screen_name  = 'baconman';

        $url = 'https://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name='.$screen_name;

        $list = curl($url,'GET');

        $followers_ids = json_decode($list);

        $user_detail = 'https://api.twitter.com/1/users/lookup.json?user_id='.implode(',',$followers_ids->ids).'&include_entities=true';
        $details = curl($user_detail,'GET');

function curl($url, $method = 'get', $header = null, $postdata = null, $includeheader=FALSE, $timeout = 60)
{
$s = curl_init();

curl_setopt($s,CURLOPT_URL, $url);
if ($header)
    curl_setopt($s,CURLOPT_HTTPHEADER, $header);

/*if ($this->debug)*/
curl_setopt($s,CURLOPT_VERBOSE, FALSE);

curl_setopt($s,CURLOPT_TIMEOUT, $timeout);
curl_setopt($s,CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($s,CURLOPT_MAXREDIRS, 3);
curl_setopt($s,CURLOPT_RETURNTRANSFER, true);
curl_setopt($s,CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($s,CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($s,CURLOPT_COOKIEFILE, 'cookie.txt');

if(strtolower($method) == 'post')
{
    curl_setopt($s,CURLOPT_POST, true);
    curl_setopt($s,CURLOPT_POSTFIELDS, $postdata);
}
else if(strtolower($method) == 'delete')
{
    curl_setopt($s,CURLOPT_CUSTOMREQUEST, 'DELETE');
}
else if(strtolower($method) == 'put')
{
    curl_setopt($s,CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($s,CURLOPT_POSTFIELDS, $postdata);
}

curl_setopt($s,CURLOPT_HEADER, $includeheader);
//curl_setopt($s,CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1');
curl_setopt($s, CURLOPT_SSL_VERIFYPEER, false);


$html   = curl_exec($s);
$status = curl_getinfo($s, CURLINFO_HTTP_CODE);


curl_close($s);

return $html;
}

这篇关于获取 Twitter 用户关注的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆