このサイトを参考に
php
1<?php 2?> 3 <script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> 4 <script> 5 6 7 var clientId = '自分のID'; 8 var cristianoUserId = '取得したいユーザID'; 9 $.ajax({ 10 url: 'https://api.instagram.com/v1/users/' + cristianoUserId + 11 '/media/recent?client_id=' + clientId, 12 type: 'GET', 13 dataType: 'jsonp' 14 }).done(function (data) { 15 16 $(data.data).each(function(i) { 17 $('<img>', { 18 src: this.images.low_resolution.url, 19 width: this.images.low_resolution.width, 20 height: this.images.low_resolution.height 21 }).appendTo($('body')); 22 if i===9 return false; 23 }); 24 console.log(data); 25 }).error(function (err) { 26 }); 27 28 29 30</script> 31 32<html> 33<head> 34 <meta charset='UTF-8'> 35</head> 36<body> 37 38</body> 39</html>
というコードを作ったのですが、コンソールに
insta.php:20 Uncaught SyntaxError: Unexpected identifier
というエラーが起きました。原因は分るでしょうか。
該当する20行目はここです。height: this.images.low_resolution.height
【補足】
①width: this.images.low_resolution.width,
height: this.images.low_resolution.height
を削除
②ifの()を付ける。
これでエラーは起きなくなりました。
しかし、
width: this.images.low_resolution.width,
height: this.images.low_resolution.height
がないと画像がbodyに表示されないので、何かいい案ないでしょうか。あと、小さいことですがhtmlとheadの場所おかしかったので、先頭に持ってきました。
【補足2】
error_message : "The access_token provided is invalid." error_type : "OAuthAccessTokenException"
見落としていましたが、先ほどのコード修正の後こういったエラーが出てきました。手法は、参考サイトの通りなのですが、ちょっと難しそうです。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。