Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.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
Google bigquery 我想从PHP脚本查询Google大查询数据集_Google Bigquery - Fatal编程技术网

Google bigquery 我想从PHP脚本查询Google大查询数据集

Google bigquery 我想从PHP脚本查询Google大查询数据集,google-bigquery,Google Bigquery,我已经下载了用于访问GoogleAPI的GoogleAPI php客户端。 我的代码是 include_once“templates/base.php”; echo页面标题(“简单API访问”); 设置包含路径(“../src/”。路径分隔符。获取包含路径(); 需要一次“Google/Client.php”; 需要_once“Google/Service/Bigquery.php”; $client=新的Google_客户端(); $client->setApplicationName(“我的

我已经下载了用于访问GoogleAPI的GoogleAPI php客户端。 我的代码是
include_once“templates/base.php”;
echo页面标题(“简单API访问”);
设置包含路径(“../src/”。路径分隔符。获取包含路径();
需要一次“Google/Client.php”;
需要_once“Google/Service/Bigquery.php”;
$client=新的Google_客户端();
$client->setApplicationName(“我的应用程序名”);
$apiKey=“----我的api密钥----”;
$client->setDeveloperKey($apiKey);
定义(“项目ID”,我的项目ID);
定义(“数据集_ID”、“我的数据集ID”);
$service=newgoogle\u service\u Bigquery($client);
$results=$service->tables->listTables(项目ID、数据集ID);
打印(结果)

如果我运行上面的文件,它会给出错误:致命错误:未捕获异常“Google_Service_exception”,并在C:\xampp\htdocs\test\Google api php客户端主机(2)\Google api php客户端主机\src\Google\Http\REST.php:80堆栈跟踪:#0 C:\xampp\htdocs\test\Google api php客户端主机(2)\google api php client master\src\google\Http\REST.php(44):google_Http_REST::decodeHttpResponse(对象(google_Http_请求))\1c:\xampp\htdocs\test\google api php client master(2)\google api php client master\src\google\client.php(499):google_Http_REST::execute(对象(google_客户端),对象(google_Http_请求))#2 C:\xampp\htdocs\test\google api php客户端主控程序(2)\google api php客户端主控程序\src\google\Service\Resource.php(195):google\u客户端->执行(对象(google\u Http\u请求))#3 C:\xampp\htdocs\test\google api php客户端主控程序(2)\google api php客户端主控程序\src\google\Service\B在C:\xampp\htdocs\test\google\api php客户端主控程序(2)中\google api php client master\src\google\Http\REST.php第80行

您需要使用OAUTH2.0对应用程序进行身份验证

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

if (isset($_SESSION['service_token'])) {
    $client->setAccessToken($_SESSION['service_token']);
}
$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);
}
$_SESSION['service_token'] = $client->getAccessToken();
var_dump($_SESSION);
$bq = new Google_Service_Bigquery($client);

可能与我在安装了XAMPP服务器的本地主机上运行的文件重复,上面的错误表示需要登录这意味着什么?这意味着您忘记了使用OAUTH2.0对应用程序进行身份验证请参阅链接示例我通过设置所需参数对我的应用程序进行了身份验证,但收到错误:致命错误:未捕获异常“Google_auth_exception”,并显示消息“错误刷新OAUTH2令牌,消息:”{“error”:OAuth2.php:327,OAuth2.php(289)中的“invalid_-grant”}'':Google_-Auth_-OAuth2->refreshTokenRequest(数组)感谢您对Oath2.0的帮助问题现已解决通过尝试此操作,我收到错误-致命错误:未捕获异常“Google_-Auth_-exception”,并显示消息“错误刷新OAuth2令牌,消息:'{“error”:“invalid_-grant”}“”在OAuth2.php:327,OAuth2.php(289):Google_Auth_OAuth2->refreshTokenRequest(数组)面临相同问题致命错误:未捕获异常“Google_Auth_exception”,消息为“刷新OAuth2令牌时出错,消息:“{”错误“:“授予无效”}“”在OAuth2.php中:327 plz帮助任何人如果您仍然必须使用OAuth,开发人员密钥有什么意义?