Google PHP API with Fusion Tables - 尝试使用我自己的表的 PHP 更新单元格值.50



我一直在到处寻找一些关于使用Google PHP API的文档,这是我设法得到的。在"sql"函数中,Google API代码中有一行至关重要的"__call('sql'....)" - 但这会导致500服务器错误。谁能帮我解决我可能出错的地方?我最初打算通过 Javascript 调用 UPDATE 函数,该函数返回"401 未经授权" - 但在尝试让 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'");

我刚刚将我的google-api-php-client更新到最新版本(r476)并创建了一个UPDATE示例,这对我有用。我在您的代码中找不到明显的错误。

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

最新更新