Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Couple of things I notice: hard coding the POST and Host headers is poor form, because curl will take care of them automatically for you. I suspect part of the problem is the insertion of the carriage return/line feed between the $videoData and the last boundary marker. That will be interpreted as part of the video file. All you need are line feeds as line separators. Maybe the carriage return renders the video file invalid? </p> <p>Maybe curl_setopt($ch, CURLOPT_VERBOSE, true) will provide some illumination.</p> <p>This works for me (on a Linux host):</p> <pre><code> /* ** https://developers.google.com/youtube/2.0/developers_guide_protocol_direct_uploading */ private function send_to_youtube($video_file, $video_info) { // Refresh access token log_msg("Obtaining access token"); $response = http_post($this-&gt;config['token_url'], array( 'client_id' =&gt; $this-&gt;config['client_id'], 'client_secret' =&gt; $this-&gt;config['client_secret'], 'refresh_token' =&gt; $video_info-&gt;refresh_key, 'grant_type' =&gt; $this-&gt;config['grant_type'] )); if ($response['http_code'] != 200) throw new Exception("Unable to obtain access token. ".print_r($response, true)); $authorization = json_decode($response['contents'], true); // Build multi-part upload request // api xml and then video file contents $boundary = uniqid(); $location = ''; if ($video_info-&gt;latitude &amp;&amp; $video_info-&gt;longitude) $location = ' &lt;georss:where&gt; &lt;gml:Point&gt; &lt;gml:pos&gt;'. $video_info-&gt;latitude .' '. $video_info-&gt;longitude .'&lt;/gml:pos&gt; &lt;/gml:Point&gt; &lt;/georss:where&gt;'; $content = '--'.$boundary.' Content-Type: application/atom+xml; charset=UTF-8 &lt;?xml version="1.0"?&gt; &lt;entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"&gt; &lt;media:group&gt; &lt;media:title type="plain"&gt;'. $video_info-&gt;title .'&lt;/media:title&gt; &lt;media:description type="plain"&gt; '. $video_info-&gt;description .' &lt;/media:description&gt; &lt;media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat"&gt; '. $video_info-&gt;category .' &lt;/media:category&gt; &lt;media:keywords&gt;'. implode(', ', $video_info-&gt;tags) .'&lt;/media:keywords&gt; &lt;/media:group&gt; '. $location .' &lt;/entry&gt; --'.$boundary.' Content-Type: '. $video_info-&gt;type .' Content-Transfer-Encoding: binary '.file_get_contents($video_file).' --'.$boundary.'--'; $headers = array( 'Authorization: '.$authorization['token_type'].' '.$authorization['access_token'], 'GData-Version: 2', 'X-GData-Key: key='.$this-&gt;config['dev_key'], 'Slug: '.$video_info-&gt;filename, 'Content-Type: multipart/related; boundary="'.$boundary.'"', 'Content-Length: '.strlen($content), 'Connection: close' ); // Upload video log_msg("Sending video '{$video_info-&gt;title}', {$video_info-&gt;url}"); $ch = curl_init($this-&gt;config['upload_url']); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $content); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if (!$http_code == 201) { // Something other than 'New Entry' log_msg("Upload Failed: ".print_r($response, true)); return new SimpleXMLElement(); } $entry = new SimpleXMLElement($response); $yt_link = $entry-&gt;link[0]-&gt;attributes()-&gt;href; log_msg("Upload Complete: ".$yt_link); return $entry; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload