title: Google YouTube API v3 :: Server-to-Server Upload Service
body: <p>Our project lets users upload videos to OUR public youtube channel when they are signed into our session. We do not want to require additional OAuth2 verification, and instead follow the follow of Google API v2. </p>
  
  <p>My code (php) and error are below, but my general question is: <strong>can my server make the insert-video POST using my API key/secrets without requiring the user to authenticate.</strong></p>
  
  <p>This question - <a href="https://stackoverflow.com/questions/8257678/google-calendar-api-v3-hardcoded-credentials">Google Calendar API v3 hardcoded credentials</a> - is very similar. Howevr if CURLing Google for the access_token is the only answer, i'll be disappointed. Thanks regardless.</p>
  
  <p><strong>Google API V3 Settings:</strong></p>
  
  <pre><code>Client ID:  xxxx.apps.googleusercontent.com
  Email address:  xxxx@developer.gserviceaccount.com
  Client secret:  xxxx
  Redirect URIs:  http://fbtabs.imagendigital.co/unilever/sedal/surprise/galeria
  JavaScript origins: https://fbtabs.imagendigital.co
  API key:    
  AIzaSyBgS-jMJQUPIiAyX20xC-encFWTPsR7qxQ
  Referers:   
  Any referer allowed
  Activated on:   Jul 4, 2013 1:21 PM
  Activated by:    xxxx@gmail.com – you
  </code></pre>
  
  <p><strong>Code:</strong> </p>
  
  <pre><code>&lt;?php
  require_once BASE_CD . 'app/src/Idframework/Tools.php';
  require_once BASE_CD . 'app/vendor/google-api-php-client/src/Google_Client.php';
  require_once BASE_CD . 'app/vendor/google-api-php-client/src/contrib/Google_YouTubeService.php';
  $client = new Google_Client();
  $client-&gt;setApplicationName('Google+ PHP Starter Application');
  $client-&gt;setClientId('xxx.apps.googleusercontent.com');
  $client-&gt;setClientSecret('xxxx');
  $client-&gt;setRedirectUri('http://fbtabs.imagendigital.co/unilever/sedal/surprise/galeria');
  $client-&gt;setDeveloperKey('xxxx');
  $youtube = new Google_YoutubeService($client);
  $snippet = new Google_VideoSnippet();
  $status = new Google_VideoStatus();
  $video = new Google_Video();
  
  if (isset($_POST['tip_desc'])) $snippet-&gt;setDescription($_POST['tip_desc']);
      $snippet-&gt;setTitle($_POST['tip_name']);
      $snippet-&gt;setTags(array("sedal","hair","pello","cabello"));
      $status-&gt;privacyStatus = "public";
  
      $video-&gt;setSnippet($snippet);
      $video-&gt;setStatus($status);
  
      $filename = $_FILES['videoInp']['tmp_name'];
      $mime = \Idframework\Tools::get_mime($filename);
  
      try {
          $part = "status";
          $obj = $youtube-&gt;videos-&gt;insert($part, $video,
                                           array("data"=&gt;file_get_contents($filename), 
                                          "mimeType" =&gt; $mime));
      } catch(Google_ServiceException $e) {
          print "Caught Google service Exception ".$e-&gt;getCode(). " message is ".$e-&gt;getMessage(). " &lt;br&gt;";
          print "Stack trace is ".$e-&gt;getTraceAsString();
      }
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <pre><code>Notice: Undefined index: content-type in C:\DATA\IDInteractive\SedalSurprise\app\vendor\google-api-php-client\src\service\Google_MediaFileUpload.php on line 99
  Caught Google service Exception 401 message is Error calling POST https://www.googleapis.com/upload/youtube/v3/videos?part=player&amp;uploadType=multipart&amp;key=AIzaSyBgS-jMJQUPIiAyX20xC-encFWTPsR7qxQ: (401) Login Required 
  Stack trace is #0 C:\DATA\IDInteractive\SedalSurprise\app\vendor\google-api-php-client\src\io\Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 C:\DATA\IDInteractive\SedalSurprise\app\vendor\google-api-php-client\src\service\Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 C:\DATA\IDInteractive\SedalSurprise\app\vendor\google-api-php-client\src\contrib\Google_YouTubeService.php(789): Google_ServiceResource-&gt;__call('insert', Array) #3 C:\DATA\IDInteractive\SedalSurprise\youtuber.php(56): Google_VideosServiceResource-&gt;insert('player', Object(Google_Video), Array) #4 {main}
  </code></pre>