LoginSignup
0
0

More than 3 years have passed since last update.

Facebook graph API でシェア数/リアクション数を取得

Last updated at Posted at 2019-10-03

アプリの作成

以下よりアプリを作成。
https://developers.facebook.com/

アプリのアクセストークンの取得

以下をリクエスト

https://graph.facebook.com/oauth/access_token?client_id=【APP_ID】&client_secret=【APP_SECRET】&grant_type=client_credentials

取得したアクセストークンが有効か確認
アクセストークンデバッガー - Facebook for Developers

wordpressのプラグイン内で結果を取得するfunction

function get_fb_graph_engagement($url) {
  if (!defined('TOKEN_FB_GRAPH')) {
    define('TOKEN_FB_GRAPH', '【トークン】');
  }
  $curl = curl_init("https://graph.facebook.com/v4.0/?id=$url/&fields=og_object{engagement},engagement&access_token=".TOKEN_FB_GRAPH);
  $option = [
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_RETURNTRANSFER => true,
  ];
  curl_setopt_array($curl, $option);
  $result = curl_exec($curl);
  $decode_res = json_decode($result);
  return $decode_res;
}

参考

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