我有一个问题,仅使用实际版本的PHP api的示例,并使用examples文件夹的“ service-account.php”文件。
原来是用于显示“ Books API”的,并且通过我的个人凭据配置可以很好地工作,但是在我的xcase中,我需要通过directory.groups.get服务进行访问以获取Google网上论坛邮件列表的会员帐户列表,所以我在其中更改了原始代码:
<?php
session_start();
include_once "templates/base.php";
/************************************************
Make an API request authenticated with a service
account.
************************************************/
require_once realpath(dirname(__FILE__) . '/../autoload.php');
/************************************************
************************************************/
// MY ACCOUNT DATA HERE
$client_id = 'xxx';
$service_account_name = 'xxx'; //Email Address
$key_file_location = 'xxx.p12'; //key.p12
$groupKey = 'xxx';
echo pageHeader("My Service Account Access");
if ($client_id == '<YOUR_CLIENT_ID>'
|| !strlen($service_account_name)
|| !strlen($key_file_location)) {
echo missingServiceAccountDetailsWarning();
}
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
//$service = new Google_Service_Books($client); //ORIGINAL
$service = new Google_Service_Directory($client);
/************************************************
************************************************/
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$authArray = array(
'https://www.googleapis.com/auth/admin.directory.group',
'https://www.googleapis.com/auth/admin.directory.group.readonly',
'https://www.googleapis.com/auth/admin.directory.group.member',
'https://www.googleapis.com/auth/admin.directory.group.member.readonly'
);
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
$authArray, //array('https://www.googleapis.com/auth/books'), //ORIGINAL
$key
);
无论我做什么,为API SDK提供授权,并使用刚在控制台开发人员的“ API凭据”面板中创建的文件和凭据,都会收到403错误。