I find it difficult to upload videos from YouTube via json and php.
I spent all night and morning trying to find code snippets from all over the Internet and.
the fact that they do not work tells me that I am not using modern syntax.
I think the clearest way to ask this question is to ask if the following properties are correct in November 2012.
so this is my initial variable declaration:
$json = file_get_contents("http://gdata.youtube.com/feeds/api/videos/{$random_text}?v=2&alt=json"); $json_data = json_decode($json);
Can someone tell me if the following is correct:
1. $video_title = $json_data->{'entry'}->{'title'}; 2. $video_date = $json_data->{'entry'}->{'published'}; 3. $video_duration = $json_data->{'entry'}->{'media:group'}->{'yt$duration'}; 4. $video_views = $json_data->{'entry'}->{'yt$statistics'}->{'viewCount'}; 5. $video_description = $json_data->{'entry'}->{'content'};
I donโt want to dilute the question by providing too much other code and information, but one of the errors I get is:
Catchable fatal error: Object of class stdClass could not be converted to string
therefore, I know that one of these properties is incorrect.
Thank you for your help, I will drink coffee and get back to that!
research
these resources are direct api links to the properties I'm trying to get and should work, but they don't seem to be :(.
feed and input structure:
https://developers.google.com/youtube/2.0/developers_guide_protocol_understanding_video_feeds#Understanding_Video_Entries
record content:
https://developers.google.com/youtube/2.0/reference#youtube_data_api_tag_entry
title tag:
https://developers.google.com/youtube/2.0/reference#youtube_data_api_tag_title
published tag:
https://developers.google.com/youtube/2.0/reference#youtube_data_api_tag_published
yt: duration tag:
https://developers.google.com/youtube/2.0/reference#youtube_data_api_tag_yt:duration
yt: statistics> viewCount label:
https://developers.google.com/youtube/2.0/reference#youtube_data_api_tag_yt:statistics
content tag (video description):
https://developers.google.com/youtube/2.0/reference#youtube_data_api_tag_content
sample code (on request)
so what i do:
- I have a form
- after sending it is processed by the php file (insert.php)
- which makes some changes to the data and then sent to the database
- I get an error in a line starting with $ final_li_code (but the code works there if json variables are not included, so the problem is with json variables)
- (I was told that this form is vulnerable to SQL injection, but it is not a public form, i.e. it is protected by htaccess / htpasswd).
this is the corresponding code from insert.php:
// basic form information $field1 = $_POST["field1"]; $field2 = $_POST["field2"]; $original_link = $_POST["link"]; // add class and video display information $random_text = array_pop(explode('/',$original_link)); $final_value = "<a class=\'youtube\' href=\"http://www.youtube.com/embed/".$random_text."?rel=0&autohide=1&showinfo=0&autoplay=0&iv_load_policy=3&wmode=transparent\">link</a>"; //start getting the youtube information $thumb = "<img src=\"http://i.ytimg.com/vi/".$random_text."/mqdefault.jpg\">"; $json = file_get_contents("http://gdata.youtube.com/feeds/api/videos/{$random_text}?v=2&alt=json"); $json_data = json_decode($json); $video_title = $json_data->entry->title; $video_date = $json_data->entry->published; $video_duration = $json_data->entry->media:group->yt:duration; $video_views = $json_data->entry->ytstatistics->viewCount; $video_description = $json_data->entry->content; // put it all together to create an <li> $final_li_code = "<li class=\".{$field1} .{$field2}\">{$thumb}<div id=\"video_information\"><h3>{$video_title}</h3><div id=\"video_information_left\"><span id=\"date\">{$video_date}</span><span id=\"duration\">{$video_duration}</span><span id=\"another_id\">{$field2}</span></div><div id=\"video_information_right\"><span id=\"video_views\">{$video_views}</span><span id=\"yet_another_id\">{$field1}</span></div><span id=\"description\">{$video_description}</span></div></li>";