php - I lose my twitter Access Token every time when I'm trying to unfollow users

11

I want to unfollow people who doesn't follow me. So I decided to use PHP-code.

$twi = new TwitterOAuth(...);

$friends    = (array)$twi->get("friends/ids", ["cursor" => -1, "screen_name" => "mylogin"]);
$followers  = (array)$twi->get("followers/ids", ["cursor" => -1, "screen_name" => "mylogin"]);

foreach ($friends['ids'] as $key => $val) {
    if (!in_array($val, $followers[ids])){
        $twi->post('friendships/destroy', ['user_id' => $user]);
    }
}

Every time when I'm trying to use this code, I have only one unfollowed user. Then I have no access to API, cause I get an error.

Error 89: Invalid or expired token

What should I do for not losing access token?

People are also looking for solutions to the problem: php - Check if $_GET is available and has specific value?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.