title: YouTube Data API - Resumable Uploads - Start a resumable session - Errors
body: <p>Running into parseError attempting to follow the "start a resumable session" YouTube Data API - Resumable Uploads documentation.</p>
  
  <p>complete list of efforts ,response and code</p>
  
  <ol>
  <li>I read on the Google APIs - "Global domain errors" page "parseError The API server cannot parse the request body." </li>
  <li>I have watched "YouTube Developers Live: Debugging &amp; Dealing with Errors" still know clue there</li>
  <li>I have read "stack over flow" for similar questions, but never get answered,or answers are still un clear </li>
  <li>the test youtube account i want to upload to has a youtube channel with videos </li>
  <li>I tried the client PHP upload API, but found out later its not a resumable upload.</li>
  <li>I thought resumable upoad would be a better option, so i dont frustrate users, by wasting there time,if there connection drops out.... </li>
  <li>I am runing PHP from hostgator account</li>
  <li>I noticed how when i did not get an error, it would return the regular snippet and status data and not the "Step 2 - Save the resumable session URI" data </li>
  <li>I am using long lived access tokens pulled from my database...in the requests, the youtube user has a channel with videos before i stored the access tokens</li>
  <li>I do check the access tokens with tokeninfo?</li>
  <li>I noticed changing "uploadType" to "uploadtype" would produce  "message": "Media type 'application/json; charset=utf-8' </li>
  </ol>
  
  <p>is not supported. Valid media types: [video/*, application/octet-stream]",following this error by changing content type to "application/octet-stream" would return "kind = youtube#video<br>
  object with json snippet,status" not the Step 2 - Save the resumable session URI, so i changed things back to "uploadType" and "application/json; charset=utf-8" now facing same parse error</p>
  
  <ol start="12">
  <li>I notice in the docs "Parameter values in the request URL must be URL-encoded." when i would urlencode() "Parameter values" it would return errors or parseError when i removed the urlencode function</li>
  <li>Even changing "Host: www.googleapis.com" to "Host: <a href="https://www.googleapis.com" rel="nofollow">https://www.googleapis.com</a>" would produce "The requested URL /upload/youtube/v3/videos was not found on this server.  That’s all we know."</li>
  <li>parse error appears to be most persistent so far</li>
  <li>I have changed urlencode() to rawurlencode() still parse error</li>
  <li>i would add charset=utf-8;multipart/form-data;application/octet-stream to content type header, still parse error</li>
  <li>I notice content type on string is text/plain; charset=us-ascii not sure if google server expects pure application/json</li>
  </ol>
  
  <p>any help would be great…</p>
  
  <pre><code>  Array
    (
        [response] =&gt; Array
            (
                [0] =&gt; {
     "error": {
      "errors": [
       {
        "domain": "global",
        "reason": "parseError",
        "message": "Parse Error"
       }
      ],
      "code": 400,
      "message": "Parse Error"
     }
    }
  
            )
  
        [headers] =&gt; [
        "POST \/upload\/youtube\/v3\/videos?uploadType=resumable&amp;part=snippet,status HTTP\/1.1",
        "Host: www.googleapis.com",
        "Authorization: Bearer ya29.vAAY5n3SJq3uCG7z4tOhehDxYj9Z7mxFENtD5PKF_dJqFlLqwCktRHTrEJkUgY_NrJD3KMetKeBA_w",
        "Content-Length: 303",
        "Content-Type: application\/json; charset=utf-8",
        "X-Upload-Content-Length: 20121",
        "X-Upload-Content-Type: video\/*"
    ]
        [curl_resource] =&gt; Resource id #18
        [video_aray] =&gt; {
        "snippet": {
            "title": "test video",
            "description": "testing api",
            "tags": [
                "any",
                "thing"
            ],
            "categoryId": 25
        },
        "status": {
            "privacyStatus": "public",
            "embeddable": true,
            "license": "youtube"
        }
    }
        [json_requestbody] =&gt; {
        "snippet": {
            "title": "test video",
            "description": "testing api",
            "tags": [
                "any",
                "thing"
            ],
            "categoryId": 25
        },
        "status": {
            "privacyStatus": "public",
            "embeddable": true,
            "license": "youtube"
        }
    }
        [request_url] =&gt; https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&amp;part=snippet,status
        [content_type_of_request] =&gt; text/plain; charset=us-ascii
        [0] =&gt; text/plain; charset=us-ascii
        [1] =&gt; text/plain; charset=us-ascii
    )
  </code></pre>
  
  <p>Source</p>
  
  <pre><code> public function startResumableSession()
      {
              $videoResource = array( 'snippet'=&gt;array('title'=&gt;"test video",'description'=&gt;"testing api",
                                      'tags'=&gt;array("any","thing"),'categoryId'=&gt;25),
                                      'status'=&gt;array('privacyStatus'=&gt;"public",'embeddable'=&gt;True,'license'=&gt;"youtube"));
              $requestBody = json_encode($videoResource,JSON_PRETTY_PRINT);
              $headers = array
                (
  
                  "POST /upload/youtube/v3/videos?uploadType=resumable&amp;part=snippet,status HTTP/1.1",
                  "Host: www.googleapis.com",
                  "Authorization: Bearer ya29.vAAY5n3SJq3uCG7z4tOhehDxYj9Z7mxFENtD5PKF_dJqFlLqwCktRHTrEJkUgY_NrJD3KMetKeBA_w",
                  "Content-Length: ".strlen($requestBody),
                  "Content-Type: application/json; charset=utf-8",
                  "X-Upload-Content-Length: 20121",
                  "X-Upload-Content-Type: video/*"
              );
              /* Parameter values in the request URL must be URL-encoded. */
              $url = "https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&amp;part=snippet,status"; 
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL,$url);
              curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
              curl_setopt($ch, CURLOPT_POSTFIELDS,urlencode($requestBody));
              curl_setopt($ch, CURLOPT_RETURNTRANSFER,TRUE);
              $result = curl_exec($ch);
              $json = json_decode($result);
              /* Check request body contenttype */
              $finfo = new finfo(FILEINFO_MIME);
              $t1=  $finfo-&gt;buffer($requestBody);
              $t2 = $finfo-&gt;buffer("test");
              $t3 = $finfo-&gt;buffer(utf8_encode("test"));
              /* debug info */
              return array(   'response'=&gt;(array)$result,
                              'headers'=&gt;json_encode($headers,JSON_PRETTY_PRINT),
                              'curl_resource'=&gt;$ch,
                              'video_aray'=&gt;json_encode($videoResource,JSON_PRETTY_PRINT),
                              'json_requestbody'=&gt;$requestBody,
                              'request_url'=&gt;$url,
                              'content_type_of_request'=&gt;$t1,$t2,$t3
                          );
      }    
  </code></pre>