YouTube数据API - 可恢复上传 - 启动可恢复的会话 - 错误

时间:2014-11-12 05:39:06

标签: upload youtube resume-upload

尝试按照“启动可恢复的会话”YouTube数据API - 可恢复的上传文档运行到parseError。

完整的工作,响应和代码列表

  1. 我在Google API上阅读 - “全局域错误”页面“parseError API服务器无法解析请求正文。”
  2. 我看过“YouTube开发者直播:调试和处理错误”仍然知道那里的线索
  3. 我已经阅读了类似问题的“堆叠过流”,但从未得到回答,或者答案仍然不明确
  4. 我要上传的测试YouTube帐户有一个带视频的YouTube频道
  5. 我尝试了客户端PHP上传API,但后来发现它不是可恢复的上传。
  6. 我认为可恢复的upoad将是一个更好的选择,所以我不会挫败用户,浪费时间,如果有连接丢失....
  7. 我正在从hostgator帐户运行PHP
  8. 我注意到当我没有收到错误时,它会返回常规片段和状态数据,而不是“第2步 - 保存可恢复的会话URI”数据
  9. 我使用从我的数据库中提取的长期存取令牌...在请求中,youtube用户在存储访问令牌之前有一个带视频的频道
  10. 我用tokeninfo检查访问令牌?
  11. 我注意到将“uploadType”更改为“uploadtype”会产生“message”:“Media type'application / json; charset = utf-8'
  12. 不受支持。有效的媒体类型:[video / *,application / octet-stream]“,通过将内容类型更改为”application / octet-stream“,此错误将返回”kind = youtube#video
    对象与json片段,状态“不是第2步 - 保存可恢复的会话URI,所以我把东西改回”uploadType“和”application / json; charset = utf-8“现在面临同样的解析错误

    1. 我在文档中注意到“请求URL中的参数值必须是URL编码的”。当我将urlencode()“参数值”时,当我删除urlencode函数时它将返回错误或parseError
    2. 即使将“主机:www.googleapis.com”更改为“主持人:https://www.googleapis.com”也会产生“此服务器上找不到请求的网址/上传/ youtube / v3 /视频。这就是我们所知道的。 “
    3. 到目前为止,
    4. 解析错误似乎最为持久
    5. 我已将urlencode()更改为rawurlencode()仍解析错误
    6. 我会添加charset = utf-8; multipart / form-data; application / octet-stream到内容类型标题,仍然解析错误
    7. 我注意到字符串上的内容类型是text / plain; charset = us-ascii不确定google服务器是否需要纯application / json
    8. 任何帮助都会很棒......

        Array
        (
            [response] => Array
                (
                    [0] => {
         "error": {
          "errors": [
           {
            "domain": "global",
            "reason": "parseError",
            "message": "Parse Error"
           }
          ],
          "code": 400,
          "message": "Parse Error"
         }
        }
      
                )
      
            [headers] => [
            "POST \/upload\/youtube\/v3\/videos?uploadType=resumable&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] => Resource id #18
            [video_aray] => {
            "snippet": {
                "title": "test video",
                "description": "testing api",
                "tags": [
                    "any",
                    "thing"
                ],
                "categoryId": 25
            },
            "status": {
                "privacyStatus": "public",
                "embeddable": true,
                "license": "youtube"
            }
        }
            [json_requestbody] => {
            "snippet": {
                "title": "test video",
                "description": "testing api",
                "tags": [
                    "any",
                    "thing"
                ],
                "categoryId": 25
            },
            "status": {
                "privacyStatus": "public",
                "embeddable": true,
                "license": "youtube"
            }
        }
            [request_url] => https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet,status
            [content_type_of_request] => text/plain; charset=us-ascii
            [0] => text/plain; charset=us-ascii
            [1] => text/plain; charset=us-ascii
        )
      

      来源

       public function startResumableSession()
          {
                  $videoResource = array( 'snippet'=>array('title'=>"test video",'description'=>"testing api",
                                          'tags'=>array("any","thing"),'categoryId'=>25),
                                          'status'=>array('privacyStatus'=>"public",'embeddable'=>True,'license'=>"youtube"));
                  $requestBody = json_encode($videoResource,JSON_PRETTY_PRINT);
                  $headers = array
                    (
      
                      "POST /upload/youtube/v3/videos?uploadType=resumable&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&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->buffer($requestBody);
                  $t2 = $finfo->buffer("test");
                  $t3 = $finfo->buffer(utf8_encode("test"));
                  /* debug info */
                  return array(   'response'=>(array)$result,
                                  'headers'=>json_encode($headers,JSON_PRETTY_PRINT),
                                  'curl_resource'=>$ch,
                                  'video_aray'=>json_encode($videoResource,JSON_PRETTY_PRINT),
                                  'json_requestbody'=>$requestBody,
                                  'request_url'=>$url,
                                  'content_type_of_request'=>$t1,$t2,$t3
                              );
          }    
      

1 个答案:

答案 0 :(得分:-1)

简单的回答是 - 你做错了。

你不应该添加" POST","主持人:"和"内容长度:"到$ he​​ader,因为它是由curl(CURLOPT_URL和CURLOPT_POSTFIELDS)生成的。

YouTube API正常运行。这不是他们的错。