LoginSignup
1
0

More than 3 years have passed since last update.

twitter api で エラーコードを取得 invalid or expired token

Last updated at Posted at 2017-10-28

twitterapi を使っていると、連携を解除される場合がある。
連携解除されているのに強引に動かすと


Exception: Invalid or expired token. in [/var/www/html/twitube.jp/vendor/mpyw/cowitter/src/Helpers/ResponseBodyDecoder.php, line 94]

といういんやらしいエラーに遭遇する。

これは laravel でも使える。

解決する方法は?

try catch を使いましょう。
まずは、try catch を使いたい場面で


use \Exception;

を読みこみ。
で続いて処理


//  エラーだったらそのユーザーの expired を 1にする
    public function checkToken($option)
    {
        try{
            $res = $this->show($option);//ここで users/show の処理
        } catch (Exception $e) {
            $hoge = $e->getCode();
            print_r($hoge);//89なら expired
            die;
        }
    }


ってな感じですね。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0