小编Rob*_*rto的帖子

Google_Service_Directory - (403)未授权访问此资源/ api

我只是使用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'])) …
Run Code Online (Sandbox Code Playgroud)

php api google-api-php-client google-admin-sdk

7
推荐指数
1
解决办法
1万
查看次数