Help us understand the problem. What is going on with this article?

ホームページにinstagramの写真を埋め込む。

More than 1 year has passed since last update.

表示部分

index.html
<div class="instagram"></div>

js部分

instagram.js
$(function(){
    var $container = $(".instagram");
    var html = "";
    $.ajax({
        url: "instagram.php",//PHPファイルURL
        type:"POST",
        dataType: "json"
    }).done(function(data){
        //通信成功時の処理
        var counter = 0;
        $.each(data.data,function(i,item){
            if(counter === 6) {
                return false;
            }
            var imgurl = item.images.low_resolution.url; //低解像度の画像のURLを取得
            var link = item.link; //リンクを取得
            html += "<div><a href='" + link + "' target='_blank'><img src='" + imgurl + "'></a></div>";
            counter++;
        });
    }).fail(function(){
        //通信失敗時の処理
        html = "<li>画像が取得できませんでした。</li>";
    }).always(function(){
        //通信完了時の処理
        $container.html(html);
    });
});

PHP部分

instagram.php
<?php
//POSTリクエストの場合のみ受付
if($_SERVER['REQUEST_METHOD'] == 'POST'){
    //アクセストークン
    $access_token = "アクセストークンを入れる";
    //JSONデータを取得して出力
    echo @file_get_contents("https://api.instagram.com/v1/users/self/media/recent/?access_token={$access_token}");
    //終了
    exit;
}
?>

これで無事に出来た。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした