我正在尝试验证服务账户,以便我可以使用客户端JSON_API库的访问令牌。
我已查看了以下文章:
我已查看了以下文章:
https://code.google.com/p/google-api-php-client/source/browse/trunk/examples/prediction/serviceAccount.php
https://code.google.com/p/google-api-php-client/wiki/UsingTheLibrary
https://developers.google.com/storage/docs/authentication#service_accounts https://developers.google.com/accounts/docs/OAuth2#scenarios
这是我的 PHP 代码
<?php
require_once 'google-api-php-client/src/Google_Client.php';
const CLIENT_ID = "";
const SERVICE_ACCOUNT_NAME = "";
const KEY_FILE = "super secret path of course ;)";
$client = new Google_Client();
// Loads the key into PKCS 12 format
$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/prediction'),
$key
)
);
$client->setClientId(CLIENT_ID);
$auth = $client->authenticate();
print $auth ? "Returned true" : "Returned false";
print "<br>";
print is_null($client->getAccessToken()) ? "It's null" : "Works";
?>
这是我的输出:
返回 true
它是 null