PHP和Google API(具体为BigQuery)

PHP和Google API(具体为BigQuery),php,google-bigquery,google-api-php-client,Php,Google Bigquery,Google Api Php Client,我目前正在尝试开发某种web应用程序,我需要它能够对超过5000万行的表执行查询。 我曾考虑过使用GoogleBigQuery来解决这个问题,但我在使用他们的API时遇到了问题。 在过去的3个小时里,我搜索了整个互联网,但我找不到一种方法来获得身份验证并仅使用PHP执行查询。对于身份验证,我找到了一种使用javascript的方法,但这对我来说并不好。我需要它是服务器端的。 整个php谷歌api文档对我来说似乎已经过时了。 Sagi,非常感谢您的帮助。以下是一个适用于我们的示例代码: sessi

我目前正在尝试开发某种web应用程序,我需要它能够对超过5000万行的表执行查询。 我曾考虑过使用GoogleBigQuery来解决这个问题,但我在使用他们的API时遇到了问题。 在过去的3个小时里,我搜索了整个互联网,但我找不到一种方法来获得身份验证并仅使用PHP执行查询。对于身份验证,我找到了一种使用javascript的方法,但这对我来说并不好。我需要它是服务器端的。 整个php谷歌api文档对我来说似乎已经过时了。
Sagi,非常感谢您的帮助。

以下是一个适用于我们的示例代码:

session_start();

define('PROJECT_ID', 'edited');
define('DATASET_ID', 'edited');
define('API_KEY', 'edited');

$client_id = 'edited';
$service_account_name = 'edited';
$key_file_location = '.ssh/privatekey-bigquery.p12';
$service_token_file_location = 'bigquery_current_service_token.json';

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");
//$client->setDeveloperKey(API_KEY);

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

// start using $client

@cmorrissey就是我试图使用的图书馆,但没有成功。我是谷歌API新手..:(这里提供了一个身份验证示例…您使用的是哪台服务器?对于任何服务器,您都可以下载一个pkey身份验证证书,而在GCE上,它甚至可以easier@FelipeHoffa托管在GoDaddy,有帮助吗?嘿,伙计,谢谢你的回复。我可以问变量$service\u token\u file\u location是什么意思吗?我需要创建我的文件吗自己