version: 1.0
lastupdate: 2022-10-31
GraphAPIを使用したトークン生成用ツール。
Facebook for Developerからマイアプリへと進み、APIを使用するためのアプリを作成。
グラフAPIエクスプローラを選択。
以下のアクセスを許可し最初のトークンを生成。
①で生成したトークン、作成したアプリのID/appsecretを入力し無期限アクセス可能なトークンを生成。
{
"access_token":"【アクセストークン】",
"token_type":"bearer"
}
{
"name": "【アプリ名】",
"id": "【ページID】"
}
ここで作成したInstagramBusinessIDとアクセストークンを使用して出力を行ってください。
{
"instagram_business_account": {
"id": "【InstagramBusinessID】"
},
"id": "【ページID】"
}
下記PHPコードを適宜出力箇所に配置して使用。
$is_domain = $_SERVER['HTTP_HOST'];
$instagram_business_id = '【Instagram Business ID】';
$instagram_token = '【無期限アクセストークン】';
$instagram_num = 【表示件数】;
$instagram_json = file_get_contents("https://graph.facebook.com/v5.0/{$instagram_business_id}?fields=name%2Cmedia.limit({$instagram_num})%7Bcaption%2Cmedia_url%2Cthumbnail_url%2Cpermalink%7D&access_token={$instagram_token}");
$instagram_json = mb_convert_encoding($instagram_json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN');
$instagram_arr = json_decode($instagram_json,true);
foreach( $instagram_arr['media']['data'] as $key => $value ){
$instagram_arr[$key] = $value;
$Link = $value['permalink'];
$imgSrc = $value['media_url'];
if($Link){
echo '<li><a href="'.$Link.'" target="_blank"><img src="'.$imgSrc.'"></a></li>';
}
}
© FULLSCALE inc.