Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PKS#12 auth从PHP使用BigQuery流_Php_Google Bigquery_Google Api Php Client_Google Cloud Platform - Fatal编程技术网

如何使用PKS#12 auth从PHP使用BigQuery流

如何使用PKS#12 auth从PHP使用BigQuery流,php,google-bigquery,google-api-php-client,google-cloud-platform,Php,Google Bigquery,Google Api Php Client,Google Cloud Platform,我正在开发一个解决方案,通过Apache/PHP服务器以每秒约3K-5K的速度将行流式传输到BigQuery中。身份验证将需要使用PKS#12 auth(“”) 我似乎找不到任何通过PHP客户端库进行流式处理和使用PKS#12 auth的示例(示例为Java或Python)。是否有人有一些最新的示例代码可以让我开始使用?我们正在使用:并且它具有基于密钥的身份验证 我们正在请求一个令牌,该令牌有一个过期时间间隔,因此我们知道何时需要请求一个新令牌。有效期为1小时 样本: set_include_p

我正在开发一个解决方案,通过Apache/PHP服务器以每秒约3K-5K的速度将行流式传输到BigQuery中。身份验证将需要使用PKS#12 auth(“”)

我似乎找不到任何通过PHP客户端库进行流式处理和使用PKS#12 auth的示例(示例为Java或Python)。是否有人有一些最新的示例代码可以让我开始使用?

我们正在使用:并且它具有基于密钥的身份验证

我们正在请求一个令牌,该令牌有一个过期时间间隔,因此我们知道何时需要请求一个新令牌。有效期为1小时

样本:

set_include_path("google-api-php/src/" . PATH_SEPARATOR . get_include_path());
require_once 'google-api-php/src/Google/Client.php';
require_once 'google-api-php/src/Google/Service/Bigquery.php';

$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");

if (!is_file($service_token_file_location)) {
    if (!is_writable($service_token_file_location)) {
        @chmod($service_token_file_location, 0777);
        if (!is_writable($service_token_file_location)) {
            die('Service token file is not writable: ' . $service_token_file_location);
        }
    }
    file_put_contents($service_token_file_location, '');
} else {
    if (!is_writable($service_token_file_location)) {
        @chmod($service_token_file_location, 0777);
        if (!is_writable($service_token_file_location)) {
            die('Service token file is not writable: ' . $service_token_file_location);
        }
    }
}
$service_token = @file_get_contents($service_token_file_location);
if (!empty($service_token)) {
    $client->setAccessToken($service_token);
}
if (!file_exists($key_file_location)) {
    die('Key file is missing: ' . $key_file_location);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
        $service_account_name, array(
    'https://www.googleapis.com/auth/bigquery',
        ), $key
);
$client->setAssertionCredentials($cred);
if ($client->getAuth()->isAccessTokenExpired()) {
    $client->getAuth()->refreshTokenWithAssertion($cred);
}
$service_token = $client->getAccessToken();
file_put_contents($service_token_file_location, $service_token);

您需要为
$service\u account\u name
$key\u file\u location
$service\u token\u file\u location

提供您自己的输入。您必须通过谷歌控制台创建一个“服务帐户”,并在服务器上下载私钥文件(.p12)。并使用以下代码

  /**
   * setup service client using key file
   * @param String $keyFileLoc location of .p12 file provided in google console
   * @param String $clientEmail client location provided in google console
   * @return Google_Service_Bigquery
   */
   function setupServiceClient($keyFileLoc,$clientEmail){
       $client = new Google_Client();
       $service = new Google_Service_Bigquery($client);
       $client->setApplicationName("My Application Name");
       $key = file_get_contents($keyFileLoc);
       $cred = new Google_Auth_AssertionCredentials(
           $clientEmail,
           array('https://www.googleapis.com/auth/bigquery'),
           $key
       ); 
       $this->client->setAssertionCredentials($cred);
       return $service;
  }

python示例是否与PHP如此不同,以至于很难移植?唯一应该不同的步骤是auth;之后,使用PKS#12进行流式处理应该与使用oauth2相同。