首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法让google-api工作

无法让google-api工作
EN

Stack Overflow用户
提问于 2014-02-28 11:37:34
回答 1查看 1.5K关注 0票数 2

我想从php cron管理我的融合表。我不能让它起作用:

代码语言:javascript
复制
<?php
//include_once "templates/base.php";
error_reporting(E_ALL-E_WARNING-E_NOTICE-E_DEPRECATED);
ini_set('display_errors',1);
session_start();

set_include_path("src/" . PATH_SEPARATOR . get_include_path());

require_once 'Google/Client.php';
require_once 'Google/Service/Fusiontables.php';
$client_id = 'given';
$service_account_name = 'given';
$key_file_location = 'given';
$tableid='given';

$client = new Google_Client();
$client->addScope("https://www.googleapis.com/auth/fusiontables");
$service=new Google_Service_Fusiontables($client);

unset($_SESSION['service_token']);
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/fusiontables'),
    $key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
  $client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();

$result=$service->table->listTable();

$insert_statement = "SELECT tytul FROM $tableid ";
$result = $service->query->sql($insert_statement);
?>

以下是研究结果:

代码语言:javascript
复制
object(Google_Service_Fusiontables_TableList)#14 (7) {
  ["itemsType":protected]=>
  string(33) "Google_Service_Fusiontables_Table"
  ["itemsDataType":protected]=>
  string(5) "array"
  ["kind"]=>
  string(22) "fusiontables#tableList"
  ["nextPageToken"]=>
  NULL
  ["collection_key":protected]=>
  string(5) "items"
  ["data":protected]=>
  array(0) {
  }
  ["processed":protected]=>
  array(0) {
  }
}

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/fusiontables/v1/query: (403) Forbidden' in /funkcje/google-api/src/Google/Http/REST.php:80 Stack trace: #0 /funkcje/google-api/src/Google/Http/REST.php(44): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request)) #1 /funkcje/google-api/src/Google/Client.php(499): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request)) #2 /funkcje/google-api/src/Google/Service/Resource.php(195): Google_Client->execute(Object(Google_Http_Request)) #3 /funkcje/google-api/src/Google/Service/Fusiontables.php(682): Google_Service_Resource->call('sql', Array, 'Google_Service_...') #4 /funkcje/google-api/fusion-tables.php(79): Google_Service_Fusiontables_Query_Resource->sql('SELECT tytul FR...') #5 {main} thrown in /funkcje/google-api/src/Google/Http/REST.php on line 80

如您所见,我连接了API (第一个结果),但它没有返回任何表(在dev控制台中,它返回两个表)--就好像我连接到了不同的帐户.

我正在以服务帐户的方式连接。如果我连接为web应用程序的客户端ID,所有工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-28 14:19:10

发现:https://groups.google.com/d/msg/google-api-php-client/9d2lQAppTvg/o5QGhsXiAQIJ

您必须从google api服务中向文档用户添加新用户。

  • 选择Google文档中的文档(FT)
  • 点击“共享”
  • 选择“添加人员”
  • 输入您的服务帐户电子邮件地址,例如myservice...@developer.gserviceaccount.com
  • 确保“可以编辑”被选中。
  • 取消“通过电子邮件通知人们”
  • 单击“共享和保存”
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22094122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档