"试图获得非对象的属性" Twitter API中的错误 - 用户/查找

时间:2014-11-21 13:57:43

标签: php api twitter error-handling

我尝试通过“friends / ids”和“users / lookup”请求获得5000个关注者。 但程序中断错误消息:“试图获取非对象的属性”在这一行

$user = $twitter->get("https://api.twitter.com/1.1/users/lookup.json?user_id=". $ids);

我该如何解决?

 <?php

    include ('twitteroauth/twitteroauth/twitteroauth.php');

    define ('CONSUMER_KEY', 'xxx');
    define ('CONSUMER_SECRET', 'xxx');
    define ('OAUTH_TOKEN', 'xxx');
    define ('OAUTH_TOKEN_SECRET', 'xxx');

    $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET);


    $param1 = array(
            'screen_name' => 'twitter',
            'stringify_ids' => true,
            'count' => 5000,
        );

    $data =  $twitter->get("https://api.twitter.com/1.1/friends/ids.json?", $param1);

    $n = 0;
    $m = 100;

    for ($i=0; $i < 50; $i++) {
    $k = 0;
    for ($j=$n; $j < $m; $j++) {
    $temp_array[$k] = $data->ids[$j];
    $ids = implode (', ', $temp_array);
    $k++;
    }
    $user = $twitter->get("https://api.twitter.com/1.1/users/lookup.json?user_id=". $ids);

    $n = $m;
    $m += 100;
    }

    echo json_encode($data->ids);
    print "\n";
    echo json_encode($user->screen_name);
    ?>

1 个答案:

答案 0 :(得分:0)

您是否检查过$ twitter实际上是一个对象?