由于我偶然发现了一些错误的解决方案(至少总是指向正确的方向)将你的 instagram 照片拉到我的网站上,我开始寻找新的方法。而且我必须在 cURL 脚本部分中实现 SSL 才能获得 instagram 提要。
但是我被困在以下部分:如何告诉我的脚本显示我的图像?
我发现,这$result->data
行得通,但如果我继续使用 PHP 这行->images
代码会给我"Trying to get property of non-object"
. 并且解码后的 JSON 的输出仍然缺乏概览性。我在这里粘贴了我现在的代码,调试模式。
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.instagram.com/v1/users/myUserID/media/recent/?access_token=myAccessToken');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$result = curl_exec($ch);
curl_close($ch);
$result=json_decode($result);
$data=($result->data);
var_dump ($data->images);
// echo "<img src="$result->images->thumbnail->url">"
?>
这是的输出json_decode
:
array(2) {
[0]=> object(stdClass)#4 (15) {
["attribution"]=> NULL
["tags"]=> array(4) {
[0]=> string(5) "remix"
[1]=> string(9) "trncfrmcn"
[2]=> string(4) "tygn"
[3]=> string(9) "mastering"
}
["type"]=> string(5) "image"
["location"]=> NULL
["comments"]=> object(stdClass)#5 (2) {
["count"]=> int(0)
["data"]=> array(0) { }
}
["filter"]=> string(7) "Toaster"
["created_time"]=> string(10) "1373149059"
["link"]=> string(34) "http://instagram.com/p/bcOOGMF5Vi/"
["likes"]=> object(stdClass)#6 (2) {
["count"]=> int(6)
["data"]=> array(4) {
[0]=> object(stdClass)#7 (4) {
["username"]=> string(13) "itsallaboutva"
["profile_picture"]=> string(77)
"http://images.ak.instagram.com/profiles/profile_186336970_75sq_1341852049.jpg"
["id"]=> string(9) "186336970"
["full_name"]=> string(16) "Victoria Anwuzia"
}
[1]=> object(stdClass)#8 (4) {
["username"]=> string(15) "eatmybeatsordie"
["profile_picture"]=> string(76)
"http://images.ak.instagram.com/profiles/profile_32709002_75sq_1355602472.jpg"
["id"]=> string(8) "32709002"
["full_name"]=> string(12) "D-Mite Beats"
}
[2]=> object(stdClass)#9 (4) {
["username"]=> string(12) "joetranmusic"
["profile_picture"]=> string(76) "http://images.ak.instagram.com/profiles/profile_32545994_75sq_1362449260.jpg"
["id"]=> string(8) "32545994"
["full_name"]=> string(8) "Joe Tran"
}
[3]=> object(stdClass)#10 (4) {
["username"]=> string(14) "xariahmarshall"
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_275171230_75sq_1362937374.jpg"
["id"]=> string(9) "275171230"
["full_name"]=> string(14) "xariahmarshall"
}
}
}
["images"]=> object(stdClass)#11 (3) {
["low_resolution"]=> object(stdClass)#12 (3) {
["url"]=> string(79) "http://distilleryimage2.s3.amazonaws.com/ded954f8e68911e2adc122000a1f9ace_6.jpg"
["width"]=> int(306)
["height"]=> int(306)
}
["thumbnail"]=> object(stdClass)#13 (3) {
["url"]=> string(79) "http://distilleryimage2.s3.amazonaws.com/ded954f8e68911e2adc122000a1f9ace_5.jpg"
["width"]=> int(150)
["height"]=> int(150)
}
["standard_resolution"]=> object(stdClass)#14 (3) {
["url"]=> string(79) "http://distilleryimage2.s3.amazonaws.com/ded954f8e68911e2adc122000a1f9ace_7.jpg"
["width"]=> int(612)
["height"]=> int(612)
}
}
["users_in_photo"]=> array(0) { }
["caption"]=> object(stdClass)#15 (4) {
["created_time"]=> string(10) "1373149155"
["text"]=> string(34) "#Mastering #TYGN #TRNCFRMCN #Remix"
["from"]=> object(stdClass)#16 (4) {
["username"]=> string(12) "liebdich9vol"
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_444541508_75sq_1372633384.jpg"
["id"]=> string(9) "444541508"
["full_name"]=> string(11) "Ian Maybach"
}
["id"]=> string(18) "494333402642093342"
}
["user_has_liked"]=> bool(false)
["id"]=> string(28) "494332600473064802_444541508"
["user"]=> object(stdClass)#17 (6) {
["username"]=> string(12) "liebdich9vol"
["website"]=> string(0) ""
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_444541508_75sq_1372633384.jpg"
["full_name"]=> string(11) "Ian Maybach"
["bio"]=> string(0) ""
["id"]=> string(9) "444541508"
}
}
[1]=> object(stdClass)#18 (15) {
["attribution"]=> NULL
["tags"]=> array(3) {
[0]=> string(6) "studio"
[1]=> string(6) "garden"
[2]=> string(4) "view"
}
["type"]=> string(5) "image"
["location"]=> NULL
["comments"]=> object(stdClass)#19 (2) {
["count"]=> int(0)
["data"]=> array(0) { }
}
["filter"]=> string(7) "Toaster"
["created_time"]=> string(10) "1372661045"
["link"]=> string(34) "http://instagram.com/p/bNrZ-sl5Xp/"
["likes"]=> object(stdClass)#20 (2) {
["count"]=> int(4)
["data"]=> array(4) {
[0]=> object(stdClass)#21 (4) {
["username"]=> string(9) "seanbabas"
["profile_picture"]=> string(76) "http://images.ak.instagram.com/profiles/profile_30025104_75sq_1369077409.jpg"
["id"]=> string(8) "30025104"
["full_name"]=> string(10) "Sean Babas"
}
[1]=> object(stdClass)#22 (4) {
["username"]=> string(12) "ginocolletti"
["profile_picture"]=> string(75) "http://images.ak.instagram.com/profiles/profile_4634400_75sq_1364847565.jpg"
["id"]=> string(7) "4634400"
["full_name"]=> string(13) "Gino Colletti"
}
[2]=> object(stdClass)#23 (4) {
["username"]=> string(13) "marygraceklee"
["profile_picture"]=> string(75) "http://images.ak.instagram.com/profiles/profile_3269702_75sq_1373251095.jpg"
["id"]=> string(7) "3269702"
["full_name"]=> string(13) "Marygrace Lee"
}
[3]=> object(stdClass)#24 (4) {
["username"]=> string(10) "cyonthefly"
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_225204950_75sq_1368426695.jpg"
["id"]=> string(9) "225204950"
["full_name"]=> string(21) "!CY ÊŽlÉŸÇɥʇuo ✈"
}
}
}
["images"]=> object(stdClass)#25 (3) {
["low_resolution"]=> object(stdClass)#26 (3) {
["url"]=> string(79) "http://distilleryimage9.s3.amazonaws.com/9f5f0300e21911e2929322000a9e0719_6.jpg"
["width"]=> int(306)
["height"]=> int(306)
}
["thumbnail"]=> object(stdClass)#27 (3) {
["url"]=> string(79) "http://distilleryimage9.s3.amazonaws.com/9f5f0300e21911e2929322000a9e0719_5.jpg"
["width"]=> int(150)
["height"]=> int(150)
}
["standard_resolution"]=> object(stdClass)#28 (3) {
["url"]=> string(79) "http://distilleryimage9.s3.amazonaws.com/9f5f0300e21911e2929322000a9e0719_7.jpg"
["width"]=> int(612)
["height"]=> int(612)
}
}
["users_in_photo"]=> array(0) { }
["caption"]=> object(stdClass)#29 (4) {
["created_time"]=> string(10) "1372900093"
["text"]=> string(21) "#studio #view #garden"
["from"]=> object(stdClass)#30 (4) {
["username"]=> string(12) "liebdich9vol"
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_444541508_75sq_1372633384.jpg"
["id"]=> string(9) "444541508"
["full_name"]=> string(11) "Ian Maybach"
}
["id"]=> string(18) "492244118468531915"
}
["user_has_liked"]=> bool(false)
["id"]=> string(28) "490238835760272873_444541508"
["user"]=> object(stdClass)#31 (6) {
["username"]=> string(12) "liebdich9vol"
["website"]=> string(0) ""
["profile_picture"]=> string(77) "http://images.ak.instagram.com/profiles/profile_444541508_75sq_1372633384.jpg"
["full_name"]=> string(11) "Ian Maybach"
["bio"]=> string(0) ""
["id"]=> string(9) "444541508"
}
}
}
我的目标是在我的网站上只有一张图片,但导航箭头可以切换到下一张。那将如何实现?