Chciałbym wprowadzić zmiany w tym kodzie, aby skrypt php pobierał film nowy z bazy i wrzucał go raz w tygodniu do Youtube automatycznie, bez wciskania formularza i send.

Mam taki kod:

  1. <?php
  2. $youtube_email = "nazwa@gmail.com";
  3. $youtube_password = "xxx";
  4.  
  5. $postdata = "Email=".$youtube_email."&Passwd=".$youtube_password."&service=youtube&source=Example";
  6. $curl = curl_init("https://www.google.com/youtube/accounts/ClientLogin");
  7. curl_setopt($curl, CURLOPT_HEADER, "Content-Type:application/x-www-form-urlencoded");
  8. curl_setopt($curl, CURLOPT_POST, 1);
  9. curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
  10. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  11. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  12. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
  13. $response = curl_exec($curl);
  14. curl_close($curl);
  15.  
  16. list($auth, $youtubeuser) = explode("\n", $response);
  17. list($authlabel, $authvalue) = array_map("trim", explode("=", $auth));
  18. list($youtubeuserlabel, $youtubeuservalue) = array_map("trim", explode("=", $youtubeuser));
  19.  
  20. $youtube_video_title = "Example"; // This is the uploading video title.
  21. $youtube_video_description = "test"; // This is the uploading video description.
  22. $youtube_video_category = "News"; // This is the uploading video category.
  23. $youtube_video_keywords = "example, video"; // This is the uploading video keywords.
  24. $data = '<?xml version="1.0"?>
  25. <entry xmlns="http://www.w3.org/2005/Atom"
  26. xmlns:media="http://search.yahoo.com/mrss/"
  27. xmlns:yt="http://gdata.youtube.com/schemas/2007">
  28. <media:group>
  29. <media:title type="plain">'.$youtube_video_title.'</media:title>
  30. <media:description type="plain">'.$youtube_video_description.'</media:description>
  31.  
  32. <media:category
  33. scheme="http://gdata.youtube.com/schemas/2007/categories.cat">'.$youtube_video_category.'</media:category>
  34. <media:keywords>'.$youtube_video_keywords.'</media:keywords>
  35. </media:group>
  36. </entry>';
  37.  
  38. $key = "AI3...X7A"; // Generated KEY here: <a href="http://code.google.com/apis/youtube/dashboard/" target="_blank">http://code.google.com/apis/youtube/dashboard/</a>.
  39.  
  40. $headers = array("Authorization: GoogleLogin auth=".$authvalue,
  41. "GData-Version: 2",
  42. "X-GData-Key: key=".$key,
  43. "Content-length: ".strlen($data),
  44. "Content-Type: application/atom+xml; charset=UTF-8");
  45.  
  46. $curl = curl_init("http://gdata.youtube.com/action/GetUploadToken");
  47. curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
  48. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  49. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  50. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  51. curl_setopt($curl, CURLOPT_POST, 1);
  52. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  53. curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
  54. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  55.  
  56. curl_setopt($curl, CURLOPT_REFERER, true);
  57. curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  58. curl_setopt($curl, CURLOPT_HEADER, 0);
  59.  
  60. $response = simplexml_load_string(curl_exec($curl));
  61.  
  62. curl_close($curl);
  63.  
  64.  
  65. ?>
  66. <script type="text/javascript">
  67. function checkForFile() {
  68. if (document.getElementById('file').value) {
  69. return true;
  70. }
  71. document.getElementById('errMsg').style.display = '';
  72. return false;
  73. }
  74. </script>
  75.  
  76. <?php
  77. $nexturl = "http://www.domena.pl"; // This parameter specifies the URL to which YouTube will redirect the user's browser when the user uploads his video file.
  78. ?>
  79.  
  80. <form action="<?php echo($response->url); ?>?nexturl=<?php echo(urlencode($nexturl)); ?>" method="post" enctype="multipart/form-data" onsubmit="return checkForFile();">
  81. <input id="file" type="file" name="file"/>
  82. <div id="errMsg" style="display:none;color:red">
  83. You need to specify a file.
  84. </div>
  85. <input type="hidden" name="token" value="<?php echo($response->token); ?>"/>
  86. <input type="submit" value="go" />
  87.  
  88. </form>
  89. </php>


Kiedy usuwam formularz i chcę dodać nowy field np:

  1. curl_setopt($curl, CURLOPT_POSTFIELDS, $plik_video);


to pojawia mi się błąd w
  1. $response = simplexml_load_string(curl_exec($curl));


jak zrobić zainicjowanie wysyłania po odświerzeniu linku ze skryptem. Próbowałem kilku rozwiązań ale coś mi nie idzie . Instrukcja API dla Youtube w php jest napisana pod klasę dla zend , tam jest użyte 'setSlug' ale to jest odniesienie do tej klasy.
https://developers.google.com/youtube/2.0/d...ploading_Videos
Dzięki z góry

dodałęm jeszcze :

  1. <media:content url="videofile.3gp" fileSize="5319922" type="video" height="270" width="480"></media:content>

i otrzymuję to:

string(549) "http://uploads.gdata.youtube.com/action/FormDataUpload/AIwbFAT....
ale po wpisaniu tego linku nie wysyła:
otrzymuję:

HTTP method GET is not supported by this URL
Error 405

Co może być nie tak, chcę po prostu wysłać wszystkie dane z plikiem do youtube , bez użycia formularza za pomocą curl_setopt.

Gdzie robię błąd?

Dzięki z góry