【发布时间】:2014-03-11 07:30:44
【问题描述】:
我已经下载了用于访问 google api 的 google-api-php-client。
我的代码是
include_once "templates/base.php";
echo pageHeader("Simple API Access");
set_include_path("../src/" . PATH_SEPARATOR . get_include_path());
require_once 'Google/Client.php';
require_once 'Google/Service/Bigquery.php';
$client = new Google_Client();
$client->setApplicationName("my application name");
$apiKey = "--------my api key----";
$client->setDeveloperKey($apiKey);
define("PROJECT_ID", my project ID);
define("DATASET_ID", "my data set ID");
$service = new Google_Service_Bigquery($client);
$results = $service->tables->listTables(PROJECT_ID, DATASET_ID);
print_r($results);
如果我运行上面的文件,它会给出错误:致命错误:未捕获异常 'Google_Service_Exception' 并在 C:\xampp\htdocs\test\google-api- 中显示消息 'Error calling GET https://www.googleapis.com/bigquery/v2/projects/projectID/datasets/datasetname/tables?key=API key: (401) Login Required' php-client-master (2)\google-api-php-client-master\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(Object(Google_Http_Request)) #1 C:\xampp\htdocs\test \google-api-php-client-master (2)\google-api-php-client-master\src\Google\Client.php(499): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request)) #2 C:\xampp\htdocs\test\google-api-php-client-master (2)\google-api-php-client-master\src\Google\Service\Resource.php(195): Google_Client->执行(对象(Google_Http_Request))#3 C:\xampp\htdocs\test\google-api-php-client-master (2)\google-api-php-client-master\src\Google\Service\B in C :\xampp\htdocs\test\google-api-php-cl ient-master (2)\google-api-php-client-master\src\Google\Http\REST.php 在第 80 行
【问题讨论】:
-
我在安装了 XAMPP 服务器的 localhost 上运行文件,上面的错误提示 Login Required 这是什么意思?
-
这意味着您忘记使用 OAUTH2.0 对您的应用程序进行身份验证,请参阅链接示例
-
我通过设置所需参数对我的应用程序进行了身份验证,但出现错误:致命错误:未捕获异常 'Google_Auth_Exception' 并带有消息'刷新 OAuth2 令牌时出错,消息:'{“error”:“invalid_grant” }'' 在 OAuth2.php:327 , OAuth2.php(289): Google_Auth_OAuth2->refreshTokenRequest(Array)
-
感谢帮助 Oath2.0 问题现已解决
标签: google-bigquery