LoginSignup
0
0

abraham/twitteroauthでAPI v2用のtokenを得る

Posted at

意外と探してもなかったので備忘録。

CLIENT_ID = 'xxxxxxxxxxxx'
CLIENT_SECRET = 'xxxxxxxxxxxx'

とOauth2用のCLIENT IDCLIENT SECRETがある中で、

//リダイレクトのときについてくるcodeを取得する
$code = $_GET['code'];

$twitter = new TwitterOAuth(CLIENT_ID,CLIENT_SECRET);
$token = $twitter->oauth2('2/oauth2/token',[
    'code' => $code,
    'redirect_uri' => REDIRECT_URI,
    'grant_type' => 'authorization_code',
    'code_verifier' => $verifier
]);
var_dump($token)

とする。

エンドポイントのURLがoauth2/tokenではなく2/oauth2/tokenになるのが意外と罠である。

0
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
0
0