0

我一直在到处寻找有关使用 Google PHP API 的一些文档,这与我设法获得的一样接近。在“sql”函数中,Google API 代码中有一行至关重要“__call('sql'....)”——但这会导致 500 服务器错误。任何人都可以帮我解决我可能出错的地方吗?我最初打算通过返回“401 未授权”的 Javascript 调用 UPDATE 函数 - 但在尝试让 oauth 为服务帐户工作时也遇到了大问题。基本上,我试图允许网站 CMS 用户更新我自己表的特定 ROWID 列中的值,并且不需要访问他们的个人数据/表等。

提前致谢!

require_once 'google-api-php-client-read-only/src/Google_Client.php';
require_once 'google-api-php-client-read-only/src/contrib/Google_FusiontablesService.php';
ini_set("DISPLAY_ERRORS",1);
error_reporting(E_ALL);

// Set your client id, service account name, and the path to your private key.
// For more information about obtaining these keys, visit:
// https://developers.google.com/console/help/#service_accounts
$CLIENT_ID = '278066061539-e80g63vcqkaj28frfn6g32vbll38onsn.apps.googleusercontent.com';
$SERVICE_ACCOUNT_NAME = '278066061539-e80g63vcqkaj28frfn6g32vbll38onsn@developer.gserviceaccount.com';

// Make sure you keep your key.p12 file in a secure location, and isn't
// readable by others.
$KEY_FILE = 'scriptonly/2655a395f392632a75bcdc139c47aa70d20d71f1-privatekey.p12';

$client = new Google_Client();
$client->setApplicationName("SIE Stop Smoking Services");

// Set your cached access token. Remember to replace $_SESSION with a
// real database or memcached.
session_start();
if (isset($_SESSION['token'])) {
 $client->setAccessToken($_SESSION['token']);
}

// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$key = file_get_contents($KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials(
    $SERVICE_ACCOUNT_NAME,
    array('https://www.googleapis.com/auth/fusiontables'),
    $key)
);

$client->setClientId($CLIENT_ID);

$client->getAccessToken();
$service = new Google_FusiontablesService($client);

$service->query->sql("UPDATE 1z3anmPv-gPfB-MQGy_qCGWabBJVCk1BCoda0qXs SET SSS_Quality='1' WHERE ROWID='4'");
4

1 回答 1

2

我刚刚将我的 google-api-php-client 更新到最新版本 (r476) 并创建了一个UPDATE 示例,它适用于我。我无法在您的代码中发现明显的错误。

您确定服务帐户有权更新表吗?请检查是否278066061539-e80g63vcqkaj28frfn6g32vbll38onsn@developer.gserviceaccount.com具有“可以编辑”权限。

于 2012-08-12T10:31:12.307 回答