Thursday, May 3, 2012

[YouTube-API] Re: cURL Upload to YouTube API

Hello,

We don't have any specific documentation on how to use cURL to
perform an upload because we don't recommend doing that. You can use
the Zend GData client library for performing uploads from PHP:

https://developers.google.com/youtube/2.0/developers_guide_php

If you'd prefer not to do that, it's certainly possible to get this
to work, but debugging your particular issue is up to you. The entire
direct upload flow is documented at a protocol level at

https://developers.google.com/youtube/2.0/developers_guide_protocol_direct_uploading

so debugging your issue is a matter of looking at the traffic you're
sending (either in a log or using Wireshark/Fiddler) and comparing it
to what we say you should be sending, and figuring out what's
different.

Cheers,
-Jeff Posnick, YouTube API Team
groups.google.com/group/youtube-api-gdata | apiblog.youtube.com |
@YouTubeDev


On Apr 28, 1:28 pm, Twarter <twar...@gmail.com> wrote:
> Hello. I am using cURL to try and direct upload post data tohttps://gdata.youtube.com/feeds/api/users/default/uploads. I am
> setting Content-Type: application/atom+xml in my header but when I
> make the call I get back the error: Content-Type: application/x-www-
> form-urlencoded is not a valid input type. I have included my cURL
> code below
>
> $postvals = array('access_token' => $video_info['token'],
>                                   'youtube_username' => $video_info['uname'],
>                       'developer_key' => 'MY-DEVELOPER-KEY',
>                       'video_filename' => 'Test Video',
>                       'boundary_string' => '--er0er89g80er',
>                                   'video_content_type' => 'video/avi',
>                                   'Binary File Data' => '@'.$video_info['filename'],
>                                   'API_XML_Request' => $string
>     );
>
>         $curlheader[0] = "Authorization: Bearer " . $video_info['token'];
>         $curlheader[1] = "Developer-Key: MY-DEVELOPER-KEY";
>         $curlheader[3] = "Content-Transfer-Encoding: binary" ;
>         $curlheader[4] = "Content-Type: application/atom+xml";
>
>     $ch = curl_init();
>         curl_setopt($ch, CURLOPT_VERBOSE, 1);   // comment after dev
>         curl_setopt($ch, CURLOPT_URL, 'https://gdata.youtube.com/feeds/api/
> users/default/uploads');
>         curl_setopt($ch, CURLOPT_POST, 1);
>         curl_setopt($ch, CURLOPT_POSTFIELDS, $attributes);
>         #curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($attributes));
>         #curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($this->request));
>         curl_setopt($ch, CURLOPT_HEADER, 1);
>         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
>         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
>         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
>
>         $response = curl_exec($ch);
>
> For the XML portion of the POST I have
>
> $string = "<?xml version='1.0'?>
>                                 <entry xmlns='http://www.w3.org/2005/Atom'xmlns:media='http://
> search.yahoo.com/mrss/' xmlns:yt='http://gdata.youtube.com/schemas/
> 2007'>
>   <media:group>
>     <media:title type='plain'>Video Title</media:title>
>     <media:description type='plain'>description</media:description>
>     <media:category scheme='http://gdata.youtube.com/schemas/2007/
> categories.cat'>Autos</media:category>
>     <media:keywords>k1,k2,k3,k4</media:keywords>
>   </media:group>
> </entry>";
>
> What am I doing wrong? The documentation isn't all that clear on how
> to formulate an upload request.

--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.

No comments:

Post a Comment