当前位置: 首页>>代码示例>>PHP>>正文


PHP expandHomeDirectory函数代码示例

本文整理汇总了PHP中expandHomeDirectory函数的典型用法代码示例。如果您正苦于以下问题:PHP expandHomeDirectory函数的具体用法?PHP expandHomeDirectory怎么用?PHP expandHomeDirectory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了expandHomeDirectory函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: getAccessToken

function getAccessToken($client)
{
    $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
    $accessToken = file_get_contents($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:ktharmabalan,项目名称:gmail,代码行数:12,代码来源:functions.php

示例3: gfGetClient

/**
 * Returns an authorized API client.
 * @return Google_Client the authorized client object
 */
function gfGetClient()
{
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET_PATH);
    $client->setAccessType('offline');
    // Load previously authorized credentials from a file.
    $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
    if (file_exists($credentialsPath)) {
        $accessToken = file_get_contents($credentialsPath);
    } else {
        echo $credentialsPath;
        die("Error: User is not authenticated.");
    }
    $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:Oshan07,项目名称:test-project,代码行数:27,代码来源:GoogleDriveFunctions.php

示例4: trim

// require __DIR__ . '/libs/constants.php';
require __DIR__ . '/libs/functions.php';
if (isset($_GET['code'])) {
    $authCode = trim($_GET['code']);
    $client = getClient();
    // Exchange authorization code for an access token.
    $accessToken = $client->authenticate($authCode);
    $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
    // Store the credentials to disk.
    if (!file_exists(dirname($credentialsPath))) {
        mkdir(dirname($credentialsPath), 0700, true);
    }
    file_put_contents($credentialsPath, $accessToken);
} else {
    // Load previously authorized credentials from a file.
    $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
    if (file_exists($credentialsPath)) {
        $accessToken = file_get_contents($credentialsPath);
    } else {
        // Request authorization from the user.
        $client = getClient();
        $authUrl = $client->createAuthUrl();
        echo "<a href='{$authUrl}'>Log in</a>";
    }
}
if (file_exists($credentialsPath)) {
    // Get the API client and construct the service object.
    $client = getClient();
    $client = getAccessToken($client);
    $service = new Google_Service_Gmail($client);
    $optParams = array();
开发者ID:ktharmabalan,项目名称:gmail,代码行数:31,代码来源:data.php

示例5: post

 public function post($to, $message)
 {
     $credentialsPath = expandHomeDirectory('~/.config/email-to-vk-vk.json');
     if (file_exists($credentialsPath)) {
         $accessToken = file_get_contents($credentialsPath);
     } else {
         // Request authorization from the user.
         // Let's pretend we are IPad application 8-)
         $authUrl = 'https://oauth.vk.com/authorize?client_id=3682744&v=5.7&scope=wall,offline&redirect_uri=http://oauth.vk.com/blank.html&display=page&response_type=token';
         printf("Open the following link in your browser:\n%s\n", $authUrl);
         print 'Enter access token: ';
         $accessToken = trim(fgets(STDIN));
         // 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);
     }
     return file_get_contents('https://api.vk.com/method/wall.post?owner_id=' . $to . '&from_group=1&message=' . urlencode($message) . '&access_token=' . $accessToken);
 }
开发者ID:asmisha,项目名称:email-to-vk,代码行数:21,代码来源:autopost.php

示例6: getClient

 /**
  * Returns an authorized API client
  *
  * @return Google_Client the authorized client object
  */
 function getClient()
 {
     global $ini, $verbose;
     static $client = NULL;
     if ($client) {
         return $client;
     }
     if (DEBUG) {
         print "Google APIs application name: {$ini['gmail_application_name']}\n" . "Google Gmail client secret file: {$ini['gmail_client_secret_path']}\n" . "Google Gmail credentials path: {$ini['gmail_credentials_path']}\n";
     }
     try {
         $client = new Google_Client();
         $client->setApplicationName($ini['gmail_application_name']);
         $client->setScopes(GMAIL_SCOPES);
         $client->setAuthConfigFile($ini['gmail_client_secret_path']);
         $client->setLoginHint($ini['gmail_username']);
         // We want access even when the user is not logged in
         $client->setAccessType('offline');
         // Load previously authorized credentials from a file.
         $credentialsPath = expandHomeDirectory($ini['gmail_credentials_path']);
         if (file_exists($credentialsPath)) {
             if (DEBUG) {
                 print "Using existing access token from {$credentialsPath}\n";
             }
             $accessToken = file_get_contents($credentialsPath);
         } else {
             // Request authorisation from the user.
             if (DEBUG) {
                 print "Requesting authorisation\n";
             }
             $authURL = $client->createAuthUrl();
             if (php_sapi_name() != 'cli') {
                 // Re-direct browser to authentication URL
                 header('Location: ' . filter_var($authURL, FILTER_SANITIZE_URL));
             }
             print "Open the following link in your browser:\n{$authURL}\n";
             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);
             if ($verbose > 3) {
                 print "Credentials saved to {$credentialsPath}\n";
             }
         }
         if (DEBUG) {
             print_r($accessToken);
             print "\n";
         }
         $client->setAccessToken($accessToken);
         // Refresh the token if it's expired.
         if ($client->isAccessTokenExpired()) {
             $client->refreshToken($client->getRefreshToken());
             $accessToken = $client->getAccessToken();
             // Check we've not lost the refresh token
             if (FALSE == strstr($accessToken, 'refresh_token')) {
                 die("Error: Refreshed access token no longer contains refresh token used to retrieve it\n");
             }
             if (DEBUG) {
                 print "Refreshed accesss token:\n";
                 print_r($accessToken);
             }
             file_put_contents($credentialsPath, $accessToken);
         }
     } catch (Exception $e) {
         print 'Exception: ' . $e->getMessage();
     }
     return $client;
 }
开发者ID:bec-uk,项目名称:bec_fault_mon,代码行数:78,代码来源:becgmail.php


注:本文中的expandHomeDirectory函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。