简体   繁体   English

获取Twitter用户关注的用户

[英]Get users a Twitter user is following

I am using the Twitter API to create a web application. 我正在使用Twitter API来创建Web应用程序。 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. 我查看了文档,但我无法找到如何执行此操作。

For example, I might be trying to get the users that baconman is following. 例如,我可能试图让baconman关注的用户。 How can I do this using the Twitter API? 如何使用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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM