2017-10-28 9 views
0

このjson形式から最初のvideoId、title、description、thumbnailsの値を高くするにはどうすればよいですか?このjson形式から最初のvideoId、タイトル、説明、サムネイルの高価値を取得する方法は?

私はこのコード

<?PHP 
$curl_value = curl_init('https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=3&search_query=test&key=youtube_api_key'); 
curl_setopt($curl_value, CURLOPT_RETURNTRANSFER, true); 
$json_exec = curl_exec($curl_value); 
$result_json = json_decode($json_exec); 
$video_id = $result_json->items[0]->videoId; 
$title = $result_json->items[0]->snippet->title; 
$description = $result_json->items[0]->snippet->description; 
$thumbnails = $result_json->items[0]->snippet->thumbnails->high; 

echo $video_id; 
echo $title; 
echo $description; 
echo $thumbnails; 
?> 

これを使用しています。

しかし、データを取得できません。どのようにすればいいですか?私は

VIDEOID = iKzRIweSBLA

タイトルを取得したい。このケースでは

= Ed Sheeran - Perfect [Official Lyric Video]

説明= Out Now: https://atlanti.cr/yt-album Subscribe to Ed's channel: http://test.ly/SubscribeToEdSheeran Follow Ed on... Facebook: ...

サムネイルは= https://i.ytimg.com/vi/iKzRIweSBLA/hqdefault.jpg

これは、JSON結果

です
{ 
"kind": "youtube#searchListResponse", 
"etag": "\"cbz3lIQ2N25AfwNr-BdxUVxJ_QY/fkLih7vu8hjlSWPap-46qmMBkKw\"", 
"nextPageToken": "CAMQAA", 
"regionCode": "TH", 
"pageInfo": { 
    "totalResults": 1000000, 
    "resultsPerPage": 3 
}, 
"items": [ 
    { 
    "kind": "youtube#searchResult", 
    "etag": "\"cbz3lIQ2N25AfwNr-BdxUVxJ_QY/xzdNtvTMaihnGappsfbZRCdysc4\"", 
    "id": { 
    "kind": "youtube#video", 
    "videoId": "iKzRIweSBLA" 
    }, 
    "snippet": { 
    "publishedAt": "2017-09-22T07:02:24.000Z", 
    "channelId": "UC0C-w0YjGpqDXGB8IHb662A", 
    "title": "Ed Sheeran - Perfect [Official Lyric Video]", 
    "description": "Out Now: https://atlanti.cr/yt-album Subscribe to Ed's channel: http://test.ly/SubscribeToEdSheeran Follow Ed on... Facebook: ...", 
    "thumbnails": { 
    "default": { 
     "url": "https://i.ytimg.com/vi/iKzRIweSBLA/default.jpg", 
     "width": 120, 
     "height": 90 
    }, 
    "medium": { 
     "url": "https://i.ytimg.com/vi/iKzRIweSBLA/mqdefault.jpg", 
     "width": 320, 
     "height": 180 
    }, 
    "high": { 
     "url": "https://i.ytimg.com/vi/iKzRIweSBLA/hqdefault.jpg", 
     "width": 480, 
     "height": 360 
    } 
    }, 
    "channelTitle": "Ed Sheeran", 
    "liveBroadcastContent": "none" 
    } 
    }, 
    { 
    "kind": "youtube#searchResult", 
    "etag": "\"cbz3lIQ2N25AfwNr-BdxUVxJ_QY/7lxJIhHg_j7RWlEuZp87hFExzCg\"", 
    "id": { 
    "kind": "youtube#video", 
    "videoId": "nfs8NYg7yQM" 
    }, 
    "snippet": { 
    "publishedAt": "2017-04-24T17:00:05.000Z", 
    "channelId": "UCwppdrjsBPAZg5_cUwQjfMQ", 
    "title": "Charlie Puth - Attention [Official Video]", 
    "description": "Download and Stream \"Attention\": https://Atlantic.lnk.to/AttentionID Pre-Order Voicenotes: https://Atlantic.lnk.to/VoicenotesID Exclusive VoiceNotes Merchandise ...", 
    "thumbnails": { 
    "default": { 
     "url": "https://i.ytimg.com/vi/nfs8NYg7yQM/default.jpg", 
     "width": 120, 
     "height": 90 
    }, 
    "medium": { 
     "url": "https://i.ytimg.com/vi/nfs8NYg7yQM/mqdefault.jpg", 
     "width": 320, 
     "height": 180 
    }, 
    "high": { 
     "url": "https://i.ytimg.com/vi/nfs8NYg7yQM/hqdefault.jpg", 
     "width": 480, 
     "height": 360 
    } 
    }, 
    "channelTitle": "Charlie Puth", 
    "liveBroadcastContent": "none" 
    } 
    }, 
    { 
    "kind": "youtube#searchResult", 
    "etag": "\"cbz3lIQ2N25AfwNr-BdxUVxJ_QY/HOZpkTZCsq-gixbvF4mQGcdiepE\"", 
    "id": { 
    "kind": "youtube#video", 
    "videoId": "kXYiU_JCYtU" 
    }, 
    "snippet": { 
    "publishedAt": "2007-03-05T08:12:00.000Z", 
    "channelId": "UCZU9T1ceaOgwfLRq7OKFU4Q", 
    "title": "Numb (Official Video) - Linkin Park", 
    "description": "Linkin Park \"Numb\" off of the album METEORA. Directed by Joe Hahn. http://www.linkinpark.com | http://LPUnderground.com iTunes: http://go.lprk.co/ml/3pb/ ...", 
    "thumbnails": { 
    "default": { 
     "url": "https://i.ytimg.com/vi/kXYiU_JCYtU/default.jpg", 
     "width": 120, 
     "height": 90 
    }, 
    "medium": { 
     "url": "https://i.ytimg.com/vi/kXYiU_JCYtU/mqdefault.jpg", 
     "width": 320, 
     "height": 180 
    }, 
    "high": { 
     "url": "https://i.ytimg.com/vi/kXYiU_JCYtU/hqdefault.jpg", 
     "width": 480, 
     "height": 360 
    } 
    }, 
    "channelTitle": "Linkin Park", 
    "liveBroadcastContent": "none" 
    } 
    } 
] 
} 

答えて

0

titledescriptionは既に動作しています。 video_idthumbnailsは非常に近いです。

$video_id = $result_json->items[0]->id->videoId; 
$title  = $result_json->items[0]->snippet->title; 
$description = $result_json->items[0]->snippet->description; 
$thumbnails = $result_json->items[0]->snippet->thumbnails->high->url; 
関連する問題