1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

FacebookグラフAPIの権限を付与する

Last updated at Posted at 2020-12-11

概要

  • グラフAPIであれこれしたい
  • FacebookのAPIはすぐ仕様変更するので大変
  • ネット記事を漁っても古くて今では使えないやり方を記載していたりする
  • 2020年12月時点で有効な手順をメモしておく
  • この記事もいつか古くなるので悪しからず

詳細

グラフAPIエクスプローラーにアクセス
初期状態の権限を確認してみる
  • "access_token"はユーザアクセストークンです
  • Facebookはトークンの種類が多いので注意
$ curl https://graph.facebook.com/me/permissions?access_token=EAAKdUj6fD******************************************3N8ZCZAzLN

{"data":[{"permission":"public_profile","status":"granted"}]}
権限を付与する
  • ここでは"e-mail"の権限を試しに付与してみる
  • 対象のアプリにプルダウンをあわせる
  • アクセス許可のプルダウンから"e-mail"を選択
  • "Generate Access Token"を押す。ここ少しわかりにくいかも。
  • 新しいアクセストークンが生成される
初期状態の権限を確認してみる
  • コマンドラインで再び権限を確認してみる
  • ”e-mail”権限が付与されていることがわかる
$ curl https://graph.facebook.com/me/permissions?access_token=EAAKdUj6fD*********************************************Fmw8ZBGUZD

{"data":[{"permission":"email","status":"granted"},{"permission":"public_profile","status":"granted"}]}
  • 同様の手順で複数権限を付与してみる
  • 問い合わせると権限が新たに付与されている事がわかる
$ curl https://graph.facebook.com/me/permissions?access_token=EAAKdUj6fD*********************************************FEZAurPQZD

{"data":[{"permission":"email","status":"granted"},{"permission":"groups_show_list","status":"granted"},{"permission":"pages_messaging","status":"granted"},{"permission":"pages_messaging_phone_number","status":"granted"},{"permission":"pages_messaging_subscriptions","status":"granted"},{"permission":"public_profile","status":"granted"}]}
  • FacebookのAPIって最初に権限付与しないと使えないってちゃんとわかりやすいところに書いておいてほしい
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?