“不足的许可”试图获取Google Spreadsheet元信息时 [英] "insufficient permissions" when trying to get Google Spreadsheet meta info

查看:140
本文介绍了“不足的许可”试图获取Google Spreadsheet元信息时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将需要很快将数据添加到现有的约1000条记录的电子表格中。我以为我想通过制作一个小的PHP页面来让我的生活更轻松,这个页面会向我显示一行数据,并为我提供一个表单,用于将我想要的数据添加到该行。电子表格位于云端硬盘中,因此将我引导至Drive API! :)

我已经下载了Google API客户端管理器,并开始使用OAuth 2.0示例(缩短了URL)。这一切都很好,但现在我试图从我需要的电子表格中提取一些元数据。无论我使用哪种驱动方式,我都会收到以下错误消息:
$ b


致命错误:带有消息的未捕获异常'Google_Service_Exception' '错误地称为POST https://www.googleapis.com/drive/v2/files :(403)权限不足'


有什么想法可能会导致这种情况?作为参考,这里是我的代码:

 <?php 
session_start();

set_include_path(google-api-php-client-master / src /。PATH_SEPARATOR。get_include_path());
require_once'Google / Client.php';
require_once'Google / Service / Drive.php';

$ client_id ='xxx';
$ client_secret ='xxx';
$ redirect_uri ='http:// localhost / coding /';

//设置客户端
$ client = new Google_Client();
$ client-> setClientId($ client_id);
$ client-> setClientSecret($ client_secret);
$ client-> setRedirectUri($ redirect_uri);
$ client-> addScope('https://www.googleapis.com/auth/drive');
$ client-> addScope('https://spreadsheets.google.com/feeds');

$ service = new Google_Service_Drive($ client);

// QUICK LOGOUT机制
if(isset($ _REQUEST ['logout'])){
unset($ _ SESSION ['access_token']);

$ b $ // HANDLE OAUTH
if(isset($ _ GET ['code'])){
$ client-> authenticate($ _ GET ['码']);
$ _SESSION ['access_token'] = $ client-> getAccessToken();
$ redirect ='http://'。 $ _SERVER ['HTTP_HOST']。 $ _SERVER [ PHP_SELF];
header('Location:'。filter_var($ redirect,FILTER_SANITIZE_URL));

$ b $ if(isset($ _ SESSION ['access_token'])&& $ _SESSION ['access_token']){
$ client-> setAccessToken($ _SESSION [ 'ACCESS_TOKEN']);
} else {
$ authUrl = $ client-> createAuthUrl();
}

//通过驱动
if($ client-> getAccessToken()){
// THIS GOES WRONG :)
$服务 - >文件 - >获得( 'XXX');
}

if(isset($ authUrl)):?>
< a class ='login'href ='<?php echo $ authUrl; ?>'>连接我!< / a>
<?php else:?>
< a class ='logout'href ='?logout'>注销< / a>
<?php endif?>


解决方案

原来只有开发者已启用Drive API控制台,而不是SDK。谢谢!


I'll be needing to add data to an existing ~1000-record spreadsheet row by row soon. I thought I want to make my life easier by making a small PHP page that would show me a row's data and provide me with a form to add the data I want to that row. the spreadsheet is in Drive so that leads me to the Drive API! :)

I've downloaded the Google API client manager and got to work with the OAuth 2.0 example (that shortens a URL). That all worked great, but now I'm trying to fetch some metadata off the spreadsheet that I need. No matter which kind of call I use regarding drive, I always get the following error:

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/drive/v2/files: (403) Insufficient Permission'

Any idea what might cause this? For reference, here's my code:

<?php
session_start();

set_include_path("google-api-php-client-master/src/" . PATH_SEPARATOR . get_include_path());
require_once 'Google/Client.php';
require_once 'Google/Service/Drive.php';

$client_id = 'xxx';
$client_secret = 'xxx';
$redirect_uri = 'http://localhost/coding/';

//SETTING UP THE CLIENT
$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope('https://www.googleapis.com/auth/drive');
$client->addScope('https://spreadsheets.google.com/feeds');

$service = new Google_Service_Drive($client);

//QUICK LOGOUT MECHANISM
if (isset($_REQUEST['logout'])) {
  unset($_SESSION['access_token']);
}

//HANDLE OAUTH
if (isset($_GET['code'])) {
  $client->authenticate($_GET['code']);
  $_SESSION['access_token'] = $client->getAccessToken();
  $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
  header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
  $client->setAccessToken($_SESSION['access_token']);
} else {
  $authUrl = $client->createAuthUrl();
}

//TALK TO DRIVE
if ($client->getAccessToken()) {
    //THIS GOES WRONG :)
    $service->files->get('xxx');
}

if (isset($authUrl)): ?>
  <a class='login' href='<?php echo $authUrl; ?>'>Connect Me!</a>
<?php else: ?>
  <a class='logout' href='?logout'>Logout</a>
<?php endif ?>

解决方案

Turns out only the Drive API was enabled in the developer console, not the SDK. Thanks!

这篇关于“不足的许可”试图获取Google Spreadsheet元信息时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆