Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting TOKEN_INVALID when uploading to YouTube
    text
    copied!<p>I'm attempting to upload a video to YouTube via the API using Zend_Gdata (Zend Framework 1.12.0). I had no problems getting direct upload to work, but browser-based upload always gives me a 400 - INVALID TOKEN error. I'm pretty sure I must be missing something vital but small enough to not notice it.</p> <p>There are two files involved in this:</p> <p><strong>index.php</strong></p> <pre><code>&lt;?php $youTubeAPIKey = '&lt;API_Key&gt;'; $username = '&lt;user&gt;'; $password = '&lt;pass&gt;'; set_include_path(get_include_path().PATH_SEPARATOR.__DIR__."/vendor"); require_once 'Zend/Loader/Autoloader.php'; Zend_Loader_Autoloader::getInstance(); try { $authenticationURL= 'https://www.google.com/accounts/ClientLogin'; $httpClient = Zend_Gdata_ClientLogin::getHttpClient( $username, $password, $service = 'youtube', $client = null, $source = 'BrowserUploaderTest', // a short string identifying your application $loginToken = null, $loginCaptcha = null, $authenticationURL); $yt = new Zend_Gdata_YouTube($httpClient, "browser upload test", "Test version 0.1", $youTubeAPIKey); $videoEntry = new Zend_Gdata_YouTube_VideoEntry(); $videoEntry-&gt;setVideoTitle("Test movie"); $videoEntry-&gt;setVideoDescription("This is a test movie"); $videoEntry-&gt;setVideoPrivate(); // @todo This must be a valid YouTube category, how to get a list of valid categories? $videoEntry-&gt;setVideoCategory('Autos'); $videoEntry-&gt;setVideoTags('cars, funny'); // Get an upload token $tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken'; $tokenArray = $yt-&gt;getFormUploadToken($videoEntry, $tokenHandlerUrl); $token = $tokenArray['token']; $url = $tokenArray['url']; // print "Token value: {$tokenArray['token']}\n url: {$tokenArray['url']}\n"; $nextUrl = "http://" . $_SERVER['HTTP_HOST'] . "/uploadDone.php"; } catch (Zend_Gdata_App_HttpException $httpException) { echo $httpException-&gt;getRawResponseBody(); } catch (Zend_Gdata_App_Exception $e) { echo $e-&gt;getMessage(); } catch (Exception $e) { print $e-&gt;getTraceAsString(); } ?&gt;&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Testing Youtube upload&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt; Url: &lt;/td&gt; &lt;td&gt; &lt;?= $url ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Token: &lt;/td&gt; &lt;td&gt; &lt;?= $token ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;form action="&lt;?= $url ?&gt;.?nexturl=&lt;?= urlencode($nextUrl) ?&gt;" enctype="multipart/form-data" method="post"&gt; &lt;input name="token" type="hidden" value="&lt;?= $token ?&gt;" /&gt; &lt;input name="file" type="file" /&gt; &lt;input type="submit" value="Upload file" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>and <strong>uploadDone.php</strong></p> <pre><code>&lt;?php print nl2br(print_r($_GET, true)); print nl2br(print_r($_POST, true)); </code></pre> <p>I've searched both on Stack Overflow and spent a couple of hours searching on Google but not found anything that solves it which leads me to believe I'm missing something dead simple. Any help would be appreciated.</p> <p><strong>A note:</strong> This code is only to test the API usage and is taken mostly from Google's Developer's guide (https://developers.google.com/youtube/2.0/developers_guide_php#Browser_based_Upload) and with a little help from the Yii framework documentation (http://www.yiiframework.com/wiki/375/youtube-api-v2-0-browser-based-uploading/). The production code will be rewritten in a more structured manner but that's not important at the moment.</p>
 

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