Follows not returning array of followers

Hello Developers! I am getting this strange error! I get the follows of a channel using /channels/:channel/follows, and I can get two of the parameters perfectly (_links, _total). The error I get is when I try to get the follows parameter, it does not return a array. Even if _total is 36567, the follows parameter returns not a array of followers. Here is how I call to the api:

    function get_follows($channel){
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL, $this->base_url . "channels/" . $channel . "/follows");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    $response = json_decode($output, true);
    curl_close($ch);

    if (isset($response['error'])) {
        echo 'Unauthorized | You have used the wrong Access Token or don\'t have the correct scope';
    } else {
        require_once(dirname(__FILE__) . '/channel/Follows.php');

        $follows = new Follows($response['_total'], $response['_links'], $response['follows']);
        return $follows;
    }
}

My follows class is the following:

<?php    
class Follows {
    public $_total, $next_link, $self_link, $follows;

    public function __construct($_total, $_links, $follows){
        $this->_total = $_total;
        $this->next_link = $_links['next'];
        $this->self_link = $_links['self'];

        if (is_array($follows)) {
            $follow_list = array();

            foreach ($follows as $value) {
                require_once(dirname(__FILE__) . '/Follow.php');
                array_push($follow_list, new Follow($value['created_at'], $value['_links'], $value['notifications'], $value['user']));
            }

            $this->$follows = $follow_list;
        } else {
            $this->$follows = $follows;
        }

    }
}

This is weird because the same exact code works for other things in the api.

Thanks in advance,
Avery.

<?php    
class Follows {
    public $_total, $next_link, $self_link, $follows;

    public function __construct($_total, $_links, $follows){
        $this->_total = $_total;
        $this->next_link = $_links['next'];
        $this->self_link = $_links['self'];

        if (is_array($follows)) {
            $follow_list = array();

            foreach ($follows as $value) {
                require_once(dirname(__FILE__) . '/Follow.php');
                array_push($follow_list, new Follow($value['created_at'], $value['_links'], $value['notifications'], $value['user']));
            }

            $this->follows = $follow_list;
        } else {
            $this->follows = $follows;
        }

    }
}

You are assigning $this->$follows instead of $this->follows I can’t see anything else wrong and I don’t have time to test your code properly right now

1 Like

What… When I set $this->follows = $follows does not matter since I already check if the list is a array which it is not! At least I think lol

You were doing $this->$follows which means $this->follows was null.

As $this->SOMEREF was being populated with the followers array instead of the follows variable of the class.

1 Like

Still do not understand what is wrong about my code lol.

These two lines:
$this->$follows = $follow_list;
$this->$follows = $follows;
need to be
$this->follows = $follow_list;
$this->follows = $follows;
instead.

1 Like

OMG, I am so stupid. Thank you so much!!

I now understand what you mean!! Sorry for being confusing!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.