private function generateCredentialsFile($api, $scopes) {

        $credentialsPath = Yii::getAlias($this->configPath) . '/' . $api . '_' . $this->getUuid() . '.json';

        $client = new Google_Client();
        $client->setAuthConfigFile($this->clientSecretPath);
        $client->setAccessType('offline');
        $client->setScopes(implode(' ', $scopes));

        // Request authorization from the user.
        $authUrl = $client->createAuthUrl();
        $this->stdout(sprintf("Open the following link in your browser:\n  %s\n", $authUrl));

        $authenticated = false;

        while (!$authenticated) {
            $authCode = $this->prompt("Enter the verification code: ");

            // Exchange authorization code for an access token.
            try {
                $accessToken = $client->authenticate($authCode);
                $authenticated = true;
            } catch (Google_Auth_Exception $e) {
                $this->stderr($e->getMessage() . "\n");
            }
        }

        // Store the credentials to disk.
        if (!is_dir(dirname($credentialsPath))) {
            mkdir(dirname($credentialsPath), 0700, true);
        }
        /** @var string $accessToken */
        file_put_contents($credentialsPath, $accessToken);

        return $credentialsPath;

    }
private function generateCredentialsFile($api, $scopes) {

        $credentialsPath = Yii::getAlias($this->configPath) . '/' . $api . '_' . $this->getUuid() . '.json';

        $client = new Google_Client();
        $client->setAuthConfigFile($this->clientSecretPath);
        $client->setAccessType('offline');
        $client->setScopes(implode(' ', $scopes));

        // Request authorization from the user.
        $authUrl = $client->createAuthUrl();
        $this->stdout(sprintf("Open the following link in your browser:\n  %s\n", $authUrl));

        $authenticated = false;

        while (!$authenticated) {
            $authCode = $this->prompt("Enter the verification code: ");

            // Exchange authorization code for an access token.
            try {
                $accessToken = $client->authenticate($authCode);
                $authenticated = true;
            } catch (Google_Auth_Exception $e) {
                $this->stderr($e->getMessage() . "\n");
            }
        }

        // Store the credentials to disk.
        if (!is_dir(dirname($credentialsPath))) {
            mkdir(dirname($credentialsPath), 0700, true);
        }
        /** @var string $accessToken */
        file_put_contents($credentialsPath, $accessToken);

        return $credentialsPath;

    }
private function generateCredentialsFile ( $ api , $ scopes ) { $ credentialsPath = Yii :: getAlias ( $ this -> configPath ) . '/' . $ api . '_' . $ this -> getUuid ( ) . '.json' ; $ client = new Google_Client ( ) ; $ client -> setAuthConfigFile ( $ this -> clientSecretPath ) ; $ client -> setAccessType ( 'offline' ) ; $ client -> setScopes ( implode ( ' ' , $ scopes ) ) ; // Request authorization from the user. $ authUrl = $ client -> createAuthUrl ( ) ; $ this -> stdout ( sprintf ( "Open the following link in your browser:\n  %s\n" , $ authUrl ) ) ; $ authenticated = false ; while ( ! $ authenticated ) { $ authCode = $ this -> prompt ( "Enter the verification code: " ) ; // Exchange authorization code for an access token. try { $ accessToken = $ client -> authenticate ( $ authCode ) ; $ authenticated = true ; } catch ( Google_Auth_Exception $ e ) { $ this -> stderr ( $ e -> getMessage ( ) . "\n" ) ; } } // Store the credentials to disk. if ( ! is_dir ( dirname ( $ credentialsPath ) ) ) { mkdir ( dirname ( $ credentialsPath ) , 0700 , true ) ; } /** @var string $accessToken */ file_put_contents ( $ credentialsPath , $ accessToken ) ; return $ credentialsPath ; }
Generates the credential file, prompting the user for the verification code
@param string $api The API name
@param Array $scopes The desired scopes
@return string
Generates the credential file prompting the user for the verification code