簡體   English   中英

通過Google Drive PHP庫API V3將文件從Google驅動器復制到我們的服務器

[英]Copying the files from google drive to our server via Google Drive PHP library API V3

我正在嘗試將Google雲端硬盤整合到我們的網站中。 我們想要做的是將文件從Drive復制到我們的服務器,你知道,有點:發送到我的文件。 當我嘗試集成時,我面臨以下錯誤

在此輸入圖像描述

我試過的代碼:

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()));
        }

您錯誤Notice: Use of undefined constant STDIN意味着它正在尋找名為STDIN的常量。 當它找不到這樣的常量時,PHP會將其解釋為字符串。 顯然,如果你以后定義了這樣的常量,這很容易破壞。 在此聲明您應該引用數組鍵以避免此類錯誤。 錯誤消息是由於PHP將隱式聲明未知標記為同名的常量字符串而導致的錯誤消息。 您還可以查看以下鏈接: 將文件從Google雲端硬盤復制到我自己的服務器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM