2017-02-08 115 views
1

我正在尝试将Google Drive集成到我们的网站中。我们想要做的就是将文件从云端硬盘复制到我们的服务器,您知道,包括:发送到我的文件。当我试图整合我对着下面的错误通过Google Drive将文件从谷歌驱动器复制到我们的服务器PHP库API V3

enter image description here

我试过代码:

require_once(ROOT . DS . 'vendor' . DS . 'google-api-php-client' . DS . 'vendor' . DS . 'autoload.php'); 

     define('APPLICATION_NAME', 'Drive API PHP Quickstart'); 
     define('CREDENTIALS_PATH', ROOT . DS . 'vendor' . DS. 'google-api-php-client' . DS .'vendor' . DS . 'drive-php-quickstart.json'); 
     define('CLIENT_SECRET_PATH', ROOT . DS . 'vendor' . DS. 'google-api-php-client' . DS . 'vendor' . DS . 'client_secret.json'); 
     define('SCOPES', implode(' ', array(\Google_Service_Drive::DRIVE_METADATA_READONLY))); 


     $client = new \Google_Client(); 
     $client->setApplicationName(APPLICATION_NAME); 
     $client->setScopes(SCOPES); 
     $client->setAuthConfig(CLIENT_SECRET_PATH); 
     $client->setAccessType('offline'); 

     // Load previously authorized credentials from a file. 
     $credentialsPath = $this->expandHomeDirectory(CREDENTIALS_PATH); 
     if (file_exists($credentialsPath)) { 
      $accessToken = json_decode(file_get_contents($credentialsPath), true); 
     } else { 
      // Request authorization from the user. 
      $authUrl = $client->createAuthUrl(); 
      printf("Open the following link in your browser:\n%s\n", $authUrl); 
      print 'Enter verification code: '; 
      $authCode = trim(fgets(STDIN)); 

      // Exchange authorization code for an access token. 
      $accessToken = $client->fetchAccessTokenWithAuthCode($authCode); 

      // Store the credentials to disk. 
      if (!file_exists(dirname($credentialsPath))) { 
       mkdir(dirname($credentialsPath), 0700, true); 
      } 
      file_put_contents($credentialsPath, json_encode($accessToken)); 
      printf("Credentials saved to %s\n", $credentialsPath); 
     } 
     $client->setAccessToken($accessToken); 


     // Refresh the token if it's expired. 
     if ($client->isAccessTokenExpired()) { 
      $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken()); 
      file_put_contents($credentialsPath, json_encode($client->getAccessToken())); 
     } 

回答

0

你错误Notice: Use of undefined constant STDIN意味着它正在寻找所谓的STDIN不变。当它没有找到这样的常量时,PHP将其解释为一个字符串。显然,如果你以后定义了这样一个常量,这很容易中断。它声明here你应该引用你的数组键来避免这样的错误。该错误消息是由于不幸的事实,即PHP将隐式地将未知标记声明为同名的常量字符串。您也可以查看此链接:Copy a file from Google Drive to my own server

相关问题