我从Instagram下载了一个JSON数组结果。我需要图片网址来显示来自Instagram的帖子。我如何检索所有图片网址?
"pagination": {},
"data": [
{
"id": "1501575131271622723_414010731",
"user": {
"id": "414010731",
"full_name": "Amir_P",
"profile_picture": "https://ig-s-b-a.akamaihd.net/hphotos-ak-xfa1/t51.2885-19/s150x150/12976101_1022789394464141_915552926_a.jpg",
"username": "amir_p__"
},
"images": {
"thumbnail": {
"width": 150,
"height": 150,
"url": "https://scontent.cdninstagram.com/t51.2885-15/s150x150/e35/c100.0.880.880/18096357_1952671591631445_7945040983308107776_n.jpg"
},
"images": {
"thumbnail": {
"width": 150,
"height": 150,
"url": "https://scontent.cdninstagram.com/t51.2885-15/s150x150/e35/c0.135.1080.1080/17268108_1309342792475888_7209542398102208512_n.jpg"
},
答案 0 :(得分:1)
我发现这种方式对我有用。
public function picture(Request $request)
{
if ($request->session()->has("access_token")) {
$access_token = $request->session()->get("access_token");
$client = new Client();
$res = $client->request('GET', 'https://api.instagram.com/v1/users/self/media/recent/?access_token=' . $access_token);
if ($res->getBody()) {
$body = $res->getBody();
$obj = \GuzzleHttp\json_decode($body);
$data = $obj->data;
foreach ($data as $img) {
$img = $img->images->thumbnail->url;
//echo "\n";
}
}
} else {
echo "there is no access token in session";
}
}