Google drive api 无法使用服务帐户将文件上载到google drive

Google drive api 无法使用服务帐户将文件上载到google drive,google-drive-api,Google Drive Api,我正在尝试使用goolge drive api的服务帐户将文件上载到“我的”中央Google drive。 我从Google drive API中获得了示例代码,但是,当我运行代码时,确切地说,当使用Google_DriveService将文件插入驱动器时,Google chrome显示“此网页不可用”。 以下是我的php代码: <?php require_once "google-api-php-client/src/Google_Client.php"; require_once "

我正在尝试使用goolge drive api的服务帐户将文件上载到“我的”中央Google drive。 我从Google drive API中获得了示例代码,但是,当我运行代码时,确切地说,当使用Google_DriveService将文件插入驱动器时,Google chrome显示“此网页不可用”。 以下是我的php代码:

<?php

require_once "google-api-php-client/src/Google_Client.php";
require_once "google-api-php-client/src/contrib/Google_DriveService.php";
require_once "google-api-php-client/src/contrib/Google_Oauth2Service.php";
session_start();

/**
 * Build and returns a Drive service object authorized with the service accounts.
 *
 * @return Google_DriveService service object.
 */
function buildService() {

    $DRIVE_SCOPE = 'https://www.googleapis.com/auth/drive';
    $SERVICE_ACCOUNT_EMAIL = '<email>@developer.gserviceaccount.com';
    $SERVICE_ACCOUNT_PKCS12_FILE_PATH = '<filename>.p12';
  $key = file_get_contents($SERVICE_ACCOUNT_PKCS12_FILE_PATH);
  $auth = new Google_AssertionCredentials(
      $SERVICE_ACCOUNT_EMAIL,
      array($DRIVE_SCOPE),
      $key);
  $client = new Google_Client();
  $client->setUseObjects(true);
  $client->setAssertionCredentials($auth);
  return new Google_DriveService($client);
}

function uploadFile($service, $mime, $src) {
    //Insert a file
    $file = new Google_DriveFile();
    $file->setMimeType($mime);
    $data = file_get_contents($src);

    try {
    //ERROR HERE: cannot insert (upload) file
        $createdFile = $service->files->insert($file,
            array(
                'data' => $data,
                'mimeType' => $mime,
                'convert' => true,
            )
        );

        return $createdFile;    
    } catch (Exception $e) {
        print "An error occurred: " . $e->getMessage();
    }   
}

//test upload file to server
$service =buildService();
$mineType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
$path = "toupload.docx";
$file = uploadFile($service,$mineType, $path);

?>


错误消息怎么说?这是来自google chrome的消息,不是来自google drive server的消息此网页不可用到114.30.45.25的连接被中断。以下是一些建议:。。。。。。。。。。。。。。。。错误101(net::ERR_CONNECTION_RESET):连接已重置。如果可以使用var_dump($e),可能会有所帮助。浏览器的消息是http 500的默认消息。不幸的是,我无法var_dump($e):(您以前尝试过Google drive api吗?我需要添加代码以使客户端授予对其驱动器的访问权限吗?我也尝试过Google apps域的委派,但仍然遇到相同的错误