當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Google_Client::setAuthConfigFile方法代碼示例

本文整理匯總了PHP中Google_Client::setAuthConfigFile方法的典型用法代碼示例。如果您正苦於以下問題:PHP Google_Client::setAuthConfigFile方法的具體用法?PHP Google_Client::setAuthConfigFile怎麽用?PHP Google_Client::setAuthConfigFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Google_Client的用法示例。


在下文中一共展示了Google_Client::setAuthConfigFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getGoogleApiClient

 /**
  * Returns an authorized API client.
  * @return Google_Client the authorized client object
  */
 private function getGoogleApiClient()
 {
     $client = new Google_Client();
     $client->setApplicationName($this->CFG['GOOGLE_API_APPLICATION_NAME']);
     $client->setScopes(Google_Service_Calendar::CALENDAR);
     $client->setAuthConfigFile($this->CFG['GOOGLE_API_CLIENT_SECRET_PATH']);
     $client->setAccessType('offline');
     // Load previously authorized credentials from a file.
     $credentialsPath = $this->CFG['GOOGLE_API_CREDENTIALS_PATH'];
     if (file_exists($credentialsPath)) {
         $accessToken = file_get_contents($credentialsPath);
     } 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->authenticate($authCode);
         // Store the credentials to disk.
         if (!file_exists(dirname($credentialsPath))) {
             mkdir(dirname($credentialsPath), 0700, true);
         }
         file_put_contents($credentialsPath, $accessToken);
         printf("Credentials saved to %s\n", $credentialsPath);
     }
     $client->setAccessToken($accessToken);
     // Refresh the token if it's expired.
     if ($client->isAccessTokenExpired()) {
         $client->refreshToken($client->getRefreshToken());
         file_put_contents($credentialsPath, $client->getAccessToken());
     }
     return $client;
 }
開發者ID:neocodesoftware,項目名稱:NeoCode-FmUsage,代碼行數:38,代碼來源:class.GoogleApi.php

示例2: getGoogleClient

 private static function getGoogleClient($config)
 {
     $client = new \Google_Client();
     $config = self::getGoogleConfig($config);
     $client->setAuthConfigFile($config);
     $userId = \HttpReceiver\HttpReceiver::get('userId', 'int');
     if (!isset($userId)) {
         $userId = \HttpReceiver\HttpReceiver::get('state', 'int');
     }
     $client->setRedirectUri($config['GOOGLEDRIVE_REDIRECT2']);
     $client->addScope(\Google_Service_Drive::DRIVE);
     return $client;
 }
開發者ID:Nickstery,項目名稱:CloudUploader-SDK,代碼行數:13,代碼來源:GoogleDriveModel.php

示例3: getClient

 public static function getClient()
 {
     $creds = GoogleSessionController::getCreds();
     $client = new Google_Client();
     $env = Config::getEnvironment();
     if ($env == 'local' && $creds->oauth_local_path) {
         $client->setAuthConfigFile($creds->oauth_local_path);
     } else {
         if ($creds->oauth_remote_path) {
             $client->setAuthConfigFile($creds->oauth_remote_path);
         } else {
             $client->setApplicationName($creds->app_name);
             $client->setClientId($creds->client_id);
             $client->setClientSecret($creds->client_secret);
         }
     }
     $client->setRedirectUri(GoogleSessionController::getRedirectURI());
     $hd = Config::get('config.google.hd');
     if ($hd) {
         $client->setHostedDomain($hd);
     }
     $client->setAccessType('offline');
     $client->addScope("https://www.googleapis.com/auth/userinfo.profile");
     $client->addScope("https://www.googleapis.com/auth/userinfo.email");
     $client->setScopes($creds->scopes);
     return $client;
 }
開發者ID:vanderlin,項目名稱:halp,代碼行數:27,代碼來源:GoogleSessionController.php

示例4: __construct

 public function __construct(\Google_Client $googleClient, $clientSecretPath)
 {
     $this->_googleClient = $googleClient;
     $this->_googleClient->setAuthConfigFile($clientSecretPath);
     $this->_googleClient->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/loginGoogle');
     $this->_googleClient->addScope(\Google_Service_Gmail::GMAIL_READONLY);
     $this->_gmailService = new \Google_Service_Gmail($this->_googleClient);
 }
開發者ID:nissnac,項目名稱:GettingStarted-Cloud,代碼行數:8,代碼來源:GoogleServices.php

示例5: load_google_analytics

 private function load_google_analytics()
 {
     WooCommerce_Grow::load_google_analytics();
     // We setup the Google Client object
     $this->client = new Google_Client();
     $this->client->setAuthConfigFile(WooCommerce_Grow::get_plugin_path() . '\\ga-config.json');
     $this->client->addScope(Google_Service_Analytics::ANALYTICS_READONLY);
     $this->analytics = new Google_Service_Analytics($this->client);
 }
開發者ID:raisonon,項目名稱:woocommerce-grow,代碼行數:9,代碼來源:class-woocommerce-grow-google-analytics.php

示例6: __construct

 /**
  * GoogleServiceProvider constructor.
  * @param $config
  */
 public function __construct()
 {
     $this->client = new \Google_Client();
     $this->projectName = config('google_cloud_storage.application');
     $this->projectBucket = config('google_cloud_storage.bucket');
     $this->authJsonFile = config('google_cloud_storage.auth_json_filename');
     $this->client->setApplicationName($this->projectName);
     $this->client->setAuthConfigFile(base_path($this->authJsonFile));
     $this->client->addScope(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);
 }
開發者ID:io-digital,項目名稱:google-cloud-storage,代碼行數:14,代碼來源:GoogleClient.php

示例7: __construct

 /**
  * GoogleServiceProvider constructor.
  * @param $config
  */
 public function __construct()
 {
     $this->client = new \Google_Client();
     $this->projectName = config('google_pub_sub.application');
     $this->authJsonFile = config('google_pub_sub.auth_json_filename');
     $this->client->setApplicationName($this->projectName);
     $this->client->setAuthConfigFile(base_path($this->authJsonFile));
     //THIS IS NEEDED FOR CHROME ENV
     //$this->client->useApplicationDefaultCredentials();
     $this->client->addScope(Google_Service_Pubsub::PUBSUB);
 }
開發者ID:io-digital,項目名稱:google-pub-sub,代碼行數:15,代碼來源:GoogleClient.php

示例8: initializeObject

 /**
  * Initialize the google calendar
  *
  * @throws \KevinDitscheid\KdCalendar\Exception\NoAuthDataException
  */
 public function initializeObject()
 {
     $this->settings = \KevinDitscheid\KdCalendar\Utility\ExtensionUtility::getMergedExtensionConfiguration();
     $this->client = new \Google_Client();
     $this->client->setApplicationName($this->settings['applicationName']);
     $this->client->setScopes(\Google_Service_Calendar::CALENDAR_READONLY);
     if ($this->settings['auth']['jsonFile']) {
         $this->client->setAuthConfigFile($this->settings['auth']['jsonFile']);
     } elseif ($this->settings['auth']['jsonString']) {
         $this->client->setAuthConfig($this->settings['auth']['jsonString']);
     } else {
         throw new \KevinDitscheid\KdCalendar\Exception\NoAuthDataException("No auth data is provided for Google Calendar!", 1454958940);
     }
     $this->client->setAccessType(self::ACCESS_TYPE_OFFLINE);
 }
開發者ID:bara0801,項目名稱:kd_calendar,代碼行數:20,代碼來源:GoogleCalendarService.php

示例9: getClient

function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET);
    $client->setAccessType('offline');
    // Load previously authorized credentials from a file.
    $credentialsPath = expandHomeDirectory(CREDENTIAL_PATH);
    if (file_exists($credentialsPath)) {
        $accessToken = file_get_contents($credentialsPath);
    } else {
        // Request authorization from the user.
        $authUrl = $client->createAuthUrl();
        printf("Open the following link in your browser:\n\n\t%s\n\n", $authUrl);
        print 'Enter verification code: ';
        $authCode = trim(fgets(STDIN));
        // Exchange authorization code for an access token.
        $accessToken = $client->authenticate($authCode);
        // Store the credentials to disk.
        if (!file_exists(dirname($credentialsPath))) {
            mkdir(dirname($credentialsPath), 0700, true);
        }
        file_put_contents($credentialsPath, $accessToken);
        printf("Credentials saved to %s\n", $credentialsPath);
    }
    $client->setAccessToken($accessToken);
    // Refresh the token if it's expired.
    if ($client->isAccessTokenExpired()) {
        $client->refreshToken($client->getRefreshToken());
        file_put_contents($credentialsPath, $client->getAccessToken());
    }
    return $client;
}
開發者ID:cmunky,項目名稱:gcontact,代碼行數:34,代碼來源:gascapi.php

示例10: getClient

/**
 * Returns an authorized API client.
 * @return Google_Client the authorized client object
 */
function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName("Study Group Finder");
    $client->setAuthConfigFile(__DIR__ . '/client_secret.json');
    $client->addScope(Google_Service_Calendar::CALENDAR);
    $client->setRedirectUri(current_url());
    if (isset($_SESSION["googleauth"])) {
        $client->setAccessToken($_SESSION["googleauth"]);
        $_SESSION["googleauth"] = NULL;
        return $client;
    }
    if (!isset($_GET['code'])) {
        // Request authorization from the user.
        $authUrl = $client->createAuthUrl();
        header("Location: {$authUrl}");
        exit(0);
    }
    $authCode = $_GET['code'];
    // Exchange authorization code for an access token.
    $accessToken = $client->authenticate($authCode);
    $_SESSION["googleauth"] = $accessToken;
    header("Location: calendar.php");
    exit(0);
}
開發者ID:magical,項目名稱:cs290-project,代碼行數:29,代碼來源:calendar.php

示例11: getClient

/**
 * Returns an authorized API client.
 * @return Google_Client the authorized client object
 */
function getClient()
{
    global $credentialsPath;
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(GAPI_SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET_PATH);
    $client->setAccessType('offline');


    if (file_exists($credentialsPath)) {
        $accessToken = file_get_contents($credentialsPath);
    } else {
        die("Please, get token via connect.php");
    }

    $client->setAccessToken($accessToken);

    // Refresh the token if it's expired.
    if ($client->isAccessTokenExpired()) {
        $client = refreshToken($client);
    }

    return $client;
}
開發者ID:ValentinNikolaev,項目名稱:Asana-GDoc-reports,代碼行數:29,代碼來源:doc_list.php

示例12: getClient

function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET_PATH);
    $client->setAccessType('offline');
    $credentialsPath = CREDENTIALS_PATH;
    if (file_exists($credentialsPath)) {
        $accessToken = file_get_contents($credentialsPath);
    } else {
        $authUrl = $client->createAuthUrl();
        printf("Open the following link in your browser:\n%s\n", $authUrl);
        print 'Enter verification code: ';
        $authCode = trim(fgets(STDIN));
        $accessToken = $client->authenticate($authCode);
        if (!file_exists(dirname($credentialsPath))) {
            mkdir(dirname($credentialsPath), 0700, true);
        }
        file_put_contents($credentialsPath, $accessToken);
        printf("Credentials saved to %s\n", $credentialsPath);
    }
    $client->setAccessToken($accessToken);
    if ($client->isAccessTokenExpired()) {
        $client->refreshToken($client->getRefreshToken());
        file_put_contents($credentialsPath, $client->getAccessToken());
    }
    return $client;
}
開發者ID:atsanna,項目名稱:PHP-Custom-Floorplan-for-Domoticz,代碼行數:29,代碼來源:gcal.php

示例13: getClient

 /**
  *  get google client
  *  @return Google_Client the authorized client object
  */
 public static function getClient()
 {
     // $scopes = implode(' ', [Google_Service_Gmail::GMAIL_READONLY]);
     /*
         $scopes = [
             'https://www.googleapis.com/auth/gmail.readonly',
             'https://www.googleapis.com/auth/gmail.modify',
             'https://www.googleapis.com/auth/gmail.send',
         ];
     */
     $scopes = ['https://mail.google.com/'];
     $clientSecretFile = conf('gmail.client_secret');
     if (!file_exists($clientSecretFile)) {
         pr('Error: client secret file not found', true);
         pr('Please create "OAuth 2.0 client IDs"');
         pr('login to https://console.developers.google.com/apis/credentials/');
         exit;
     }
     $client = new Google_Client();
     $client->setScopes($scopes);
     $client->setAuthConfigFile($clientSecretFile);
     $client->setAccessType('offline');
     // $client->setApprovalPrompt('force');
     $tokenFile = conf('gmail.access_token');
     $accessToken = self::accessToken($client, $tokenFile);
     $client->setAccessToken($accessToken);
     // Refresh the token if it's expired.
     if ($client->isAccessTokenExpired()) {
         $client->refreshToken($client->getRefreshToken());
         file_put_contents($tokenFile, $client->getAccessToken());
     }
     return $client;
 }
開發者ID:glennfriend,項目名稱:gmail-import-use-api,代碼行數:37,代碼來源:GmailApiHelper.php

示例14: getClient

function getClient()
{
    $client = new Google_Client();
    $client->setAuthConfigFile('includes/OAuth2/client_secret.json');
    $client->setAccessToken($_SESSION['access_token']);
    return $client;
}
開發者ID:villa7,項目名稱:kibbyte,代碼行數:7,代碼來源:query.php

示例15: __construct

 public function __construct(\Google_Client $client)
 {
     $client->setApplicationName("magicpi");
     $client->setScopes([\Google_Service_Calendar::CALENDAR_READONLY]);
     $client->setAuthConfigFile(__DIR__ . "/../config/piauth.json");
     $client->setAccessType('offline');
     $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/auth');
     $this->client = $client;
 }
開發者ID:amazingmikeyc,項目名稱:pi-lander,代碼行數:9,代碼來源:Authenticator.php


注:本文中的Google_Client::setAuthConfigFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。