我一直在寻找有关使用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'");
答案 0 :(得分:2)
我刚刚将我的google-api-php-client更新为最新版本(r476)并创建了UPDATE example,works for me。我无法在你的代码中发现一个明显的错误。
您确定服务帐户是否有权更新表格?请检查278066061539-e80g63vcqkaj28frfn6g32vbll38onsn@developer.gserviceaccount.com
是否具有“可以修改”权限。