<tfoot id='2bOtZ'></tfoot>
      <legend id='2bOtZ'><style id='2bOtZ'><dir id='2bOtZ'><q id='2bOtZ'></q></dir></style></legend>

      <i id='2bOtZ'><tr id='2bOtZ'><dt id='2bOtZ'><q id='2bOtZ'><span id='2bOtZ'><b id='2bOtZ'><form id='2bOtZ'><ins id='2bOtZ'></ins><ul id='2bOtZ'></ul><sub id='2bOtZ'></sub></form><legend id='2bOtZ'></legend><bdo id='2bOtZ'><pre id='2bOtZ'><center id='2bOtZ'></center></pre></bdo></b><th id='2bOtZ'></th></span></q></dt></tr></i><div id='2bOtZ'><tfoot id='2bOtZ'></tfoot><dl id='2bOtZ'><fieldset id='2bOtZ'></fieldset></dl></div>

      <small id='2bOtZ'></small><noframes id='2bOtZ'>

        • <bdo id='2bOtZ'></bdo><ul id='2bOtZ'></ul>

        将文件提交到 Google Drive

        时间:2023-07-15
        1. <legend id='sZVOO'><style id='sZVOO'><dir id='sZVOO'><q id='sZVOO'></q></dir></style></legend>
            • <bdo id='sZVOO'></bdo><ul id='sZVOO'></ul>
            • <tfoot id='sZVOO'></tfoot>

                  <i id='sZVOO'><tr id='sZVOO'><dt id='sZVOO'><q id='sZVOO'><span id='sZVOO'><b id='sZVOO'><form id='sZVOO'><ins id='sZVOO'></ins><ul id='sZVOO'></ul><sub id='sZVOO'></sub></form><legend id='sZVOO'></legend><bdo id='sZVOO'><pre id='sZVOO'><center id='sZVOO'></center></pre></bdo></b><th id='sZVOO'></th></span></q></dt></tr></i><div id='sZVOO'><tfoot id='sZVOO'></tfoot><dl id='sZVOO'><fieldset id='sZVOO'></fieldset></dl></div>

                    <tbody id='sZVOO'></tbody>

                  <small id='sZVOO'></small><noframes id='sZVOO'>

                  本文介绍了将文件提交到 Google Drive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我试图将文件提交到 Google 云端硬盘.虽然文件已上传到驱动器,但点击接受按钮后出现错误.

                  I was trying to submit file to Google Drive. Though the file is uploaded to drive, I am getting error after hitting accept button.

                  <?php
                  require_once 'google-api-php-client/src/Google_Client.php';
                  require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
                  
                  $client = new Google_Client();
                  // Get your credentials from the console
                  $client->setClientId('YOUR_CLIENT_ID');
                  $client->setClientSecret('YOUR_CLIENT_SECRET');
                  $client->setRedirectUri('http://localhost/pdf/quickstart.php');
                  $client->setScopes(array('https://www.googleapis.com/auth/drive'));
                  
                  $service = new Google_DriveService($client);
                  
                  $authUrl = $client->createAuthUrl();
                  
                  //Request authorization
                  print "Please visit:
                  $authUrl
                  
                  ";
                  print "Please enter the auth code:
                  ";
                  $authCode = trim(fgets(STDIN));
                  
                  // Exchange authorization code for access token
                  $accessToken = $client->authenticate($authCode);
                  $client->setAccessToken($accessToken);
                  
                  //Insert a file
                  $file = new Google_DriveFile();
                  $file->setTitle('My document');
                  $file->setDescription('A test document');
                  $file->setMimeType('text/plain');
                  
                  $data = file_get_contents('document.txt');
                  
                  $createdFile = $service->files->insert($file, array(
                        'data' => $data,
                        'mimeType' => 'text/plain',
                      ));
                  
                  print_r($createdFile);
                  ?>
                  

                  错误信息:

                  注意:使用未定义的常量 STDIN - 在 C:LocalServerhtdocspdfquickstart.php 中第 18 行假定为STDIN"

                  Notice: Use of undefined constant STDIN - assumed 'STDIN' in C:LocalServerhtdocspdfquickstart.php on line 18

                  警告:fgets() 期望参数 1 为资源,字符串在 C:LocalServerhtdocspdfquickstart.php 中第 18 行

                  Warning: fgets() expects parameter 1 to be resource, string given in C:LocalServerhtdocspdfquickstart.php on line 18

                  如何修复

                  推荐答案

                  STDIN 是一个命令行指令,它不是一个直接有效的 php 语句..我所做的是:

                  STDIN is a command line instruction and it isn't a direct valid php statement .. What i did was :

                  $client = new Google_Client();
                  // Get your credentials from the console
                  $client->setClientId('**********************');
                  $client->setClientSecret('*********');
                  $client->setRedirectUri('*********');
                  $client->setScopes(array('https://www.googleapis.com/auth/drive'));
                  
                  $authUrl = $client->createAuthUrl();
                  print $authurl
                  
                  $authCode = ''; // insert the verification code that you get after going to url in $authurl
                  file_put_contents('token.json', $client->authenticate($authCode));
                  

                  执行这么多后,您将在 json 文件 token.json 中获得您的身份验证信息……您可以使用以下内容上传……:

                  After executing this much you'll get your authentication info in the json file token.json ... And you can use the following to upload ... :

                  $service = new Google_DriveService($client);
                  
                  $client->setAccessToken(file_get_contents('token.json'));
                  
                  //Insert a file 
                      ..... // rest the same
                  

                  一旦你得到你的 json 不要再次运行顶级代码......每次上传/下载都使用 token.json ....

                  Once you get your json don't run the top codes again ... Just use the token.json everytime to upload/download ....

                  这篇关于将文件提交到 Google Drive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用 Google API 在团队云端硬盘中创建文件夹? 下一篇:Google-api-php 刷新令牌返回 invalid_grant

                  相关文章

                    <bdo id='VRCMC'></bdo><ul id='VRCMC'></ul>
                  <i id='VRCMC'><tr id='VRCMC'><dt id='VRCMC'><q id='VRCMC'><span id='VRCMC'><b id='VRCMC'><form id='VRCMC'><ins id='VRCMC'></ins><ul id='VRCMC'></ul><sub id='VRCMC'></sub></form><legend id='VRCMC'></legend><bdo id='VRCMC'><pre id='VRCMC'><center id='VRCMC'></center></pre></bdo></b><th id='VRCMC'></th></span></q></dt></tr></i><div id='VRCMC'><tfoot id='VRCMC'></tfoot><dl id='VRCMC'><fieldset id='VRCMC'></fieldset></dl></div>
                  <tfoot id='VRCMC'></tfoot>

                    <legend id='VRCMC'><style id='VRCMC'><dir id='VRCMC'><q id='VRCMC'></q></dir></style></legend>
                  1. <small id='VRCMC'></small><noframes id='VRCMC'>