如何在php中获取twitter(不是粉丝数)的所有追随者的详细信息?

时间:2014-03-28 10:35:54

标签: php twitter dreamweaver

这里的代码可以很好地获取关注者和跟随者的数量。但我想向每个关注者显示所有细节(图片,用户名,ID等)..实际上我通过使用方法$ followingdata = json_decode为Instagram做了这个$ instgram-> getFollowing(20)); 我为twitter做了什么。

<?php


require('http.php');
require('oauth_client.php');

$client = new oauth_client_class;
$client->debug = 1;
$client->server = 'Twitter';
$client->redirect_uri = 'http://'.$_SERVER['HTTP_HOST'].
    dirname(strtok($_SERVER['REQUEST_URI'],'?')).'/login_with_twitter.php';



$client->client_id = 'my client id'; $application_line = __LINE__;
$client->client_secret = 'my client secret';

if(strlen($client->client_id) == 0
|| strlen($client->client_secret) == 0)
    die('Please go to Twitter Apps page https://dev.twitter.com/apps/new , '.
        'create an application, and in the line '.$application_line.
        ' set the client_id to Consumer key and client_secret ... '.
        'The Callback URL must be '.$client->redirect_uri);

if(($success = $client->Initialize()))
{
    if(($success = $client->Process()))
    {
        if(strlen($client->access_token))
        {
            $success = $client->CallAPI(
                     'https://api.twitter.com/1.1/account/verify_credentials.json', 
                'GET', array(), array('FailOnAccessError'=>true),   $user);
        }
    }
    $success = $client->Finalize($success);
}
if($client->exit)
    exit;
if($success)
{

$following =$user->friends_count;
$followers =$user->followers_count;
?>

1 个答案:

答案 0 :(得分:0)

您可以尝试以下方式:

        using (WebClient client = new WebClient())
        {
            string url = "http://twitter.com/users/show.xml?screen_name=[username]";

            string response = client.DownloadString(url);
        }

此致