Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
谷歌驱动API-可恢复上传使用PHP Curl无响应_Php_Wordpress_Curl_Google Drive Api - Fatal编程技术网

谷歌驱动API-可恢复上传使用PHP Curl无响应

谷歌驱动API-可恢复上传使用PHP Curl无响应,php,wordpress,curl,google-drive-api,Php,Wordpress,Curl,Google Drive Api,我正在实现一个文件上传,使我能够处理大文件,所以我决定集成到谷歌驱动器。我阅读了所有关于V3API的文档,但它在我的本地设置(XAMPP localhost)中似乎不起作用 我决定不使用GoogleSDK,因为我只使用GoogleDrive 我的PHP curl不会返回它一直加载的任何内容,直到出现错误显示“curl error:Operation在60001毫秒后超时,收到0字节”(即使将超时更改为几分钟) 我想我添加的代码是正确的,并根据他们的要求遵循了Google Drive文档 我添加了

我正在实现一个文件上传,使我能够处理大文件,所以我决定集成到谷歌驱动器。我阅读了所有关于V3API的文档,但它在我的本地设置(XAMPP localhost)中似乎不起作用

我决定不使用GoogleSDK,因为我只使用GoogleDrive

我的PHP curl不会返回它一直加载的任何内容,直到出现错误显示“curl error:Operation在60001毫秒后超时,收到0字节”(即使将超时更改为几分钟)

我想我添加的代码是正确的,并根据他们的要求遵循了Google Drive文档

  • 我添加了这个函数来发送初始请求并获取可恢复的会话URI
  • 会话URI:

  • 下面是我使用curl上传的代码
  • 对于测试,这些文件来自我的表单,带有
    标记

    我使用了3MB(png/jpg)文件的精确大小

    这是我的卷曲头视图

    Array
    (
        [0] => Authorization: Bearer ya29.a0AfH6SMCgZfuRQphJDkHO1zx_ZvQSAE-h51TSW2Aj-lKuglEXVSFiybOC1Rx-PutpB-IeYQc-WewmoqVClC8SKn3fOoItl7aAzyG3k5K8KjNQU3oCEoPhuOv1Q1wXF1IxiiOSSAQ1MaChkH02DaB2yucgNB
        [1] => Content-Length: 524289
        [2] => Content-Type: image/png
        [3] => Content-Range: bytes 0-524288/2965095
    )
    
  • 我还尝试刷新访问令牌
  • 有没有人经历过这样的问题?我不知道这是否与我的xampp有关,或者谷歌因为多次测试而阻止了我的api请求

    public function upload( $file = null, $upload_folder = null ) {
       
        $location_url = $this->initial_request( $file );
    
        // Files
        $file_size  = (int)$file['size']; // 2965095 bytes (3MB sample file)
        $file_type = $file['type'];
        
        // Chunks Args
        $chunk_size     = 256 * 1024 * 2; // 0.5MB per chunk (524288 bytes)
        $chunk_start    = 0;
        $chunk_end      = min( $chunk_size, $file_size - 1 ); // Get the lowest value
        $chunk_file     = $this->get_chunk( $file, 0, $chunk_size ); // Getting first chunk
        
        $token = trim( $this->access_token );
        $length = ( $chunk_end - $chunk_start + 1 ); //524289 - size of first chunk
        
        $ch = curl_init() ;
    
        curl_setopt( $ch, CURLOPT_URL, $location_url ) ;
        curl_setopt( $ch, CURLOPT_PORT , 443 ) ;
        curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT" ) ;
        curl_setopt( $ch, CURLOPT_ENCODING, '');
        curl_setopt( $ch, CURLOPT_BINARYTRANSFER, true ) ;
        curl_setopt( $ch, CURLOPT_POSTFIELDS, $chunk_file ) ;
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true) ;
        curl_setopt( $ch, CURLOPT_HEADER, true ) ;
        curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt( $ch, CURLOPT_TIMEOUT, 120); //timeout in seconds
    
        curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
                "Authorization: Bearer {$token}",
                "Content-Length: {$length}",
                "Content-Type: {$file_type}",
                "Content-Range: bytes {$chunk_start}-{$chunk_end}/{$file_size}"
            ) 
        );
    
        $response = curl_exec( $ch );
    
        $post_transaction_info = curl_getinfo( $ch ) ;
    
        if( $response === false ) {
            echo 'Curl error: ' . curl_error($ch);
        }else {
            var_dump( $response );
            print_r($post_transaction_info);
        }
    
        curl_close( $ch ) ;
    
    }
    
    Array
    (
        [0] => Authorization: Bearer ya29.a0AfH6SMCgZfuRQphJDkHO1zx_ZvQSAE-h51TSW2Aj-lKuglEXVSFiybOC1Rx-PutpB-IeYQc-WewmoqVClC8SKn3fOoItl7aAzyG3k5K8KjNQU3oCEoPhuOv1Q1wXF1IxiiOSSAQ1MaChkH02DaB2yucgNB
        [1] => Content-Length: 524289
        [2] => Content-Type: image/png
        [3] => Content-Range: bytes 0-524288/2965095
    )