发布于2024-10-31 15:35 阅读(100) 评论(0) 点赞(5) 收藏(2)
我正在使用 Google SDK PHP 执行批量请求以获取 Google Classroom 中的课程列表。我的脚本使用服务帐户访问 sguite 数据,无需用户确认。如果我关闭批处理模式,它会运行正常,但当我打开批处理模式时会出现错误 这是我的代码
<?php
namespace app\Libs;
use Google_Client;
use Google_Service_Classroom;
class ClassRoom
{
private $api, $adminEmail, $client;
const SCOPES = ['https://www.googleapis.com/auth/classroom.course-work.readonly','https://www.googleapis.com/auth/classroom.courses','https://www.googleapis.com/auth/classroom.courses.readonly','https://www.googleapis.com/auth/classroom.coursework.me','https://www.googleapis.com/auth/classroom.coursework.me.readonly','https://www.googleapis.com/auth/classroom.coursework.students','https://www.googleapis.com/auth/classroom.coursework.students.readonly','https://www.googleapis.com/auth/classroom.profile.emails','https://www.googleapis.com/auth/classroom.profile.photos','https://www.googleapis.com/auth/classroom.rosters','https://www.googleapis.com/auth/classroom.rosters.readonly','https://www.googleapis.com/auth/classroom.student-submissions.me.readonly','https://www.googleapis.com/auth/classroom.student-submissions.students.readonly','https://www.googleapis.com/auth/classroom.guardianlinks.students'];
function __construct($adminEmail)
{
$this->adminEmail = $adminEmail;
$client = new Google_Client();
$client->setAuthConfig('config.json');
$client->setScopes(self::SCOPES);
$client->setSubject($adminEmail);
$this->api = new Google_Service_Classroom($client);
}
function addClasses()
{
$client = $this->api->getClient();
$client->setUseBatch(true);
$batch = new Google_Http_Batch($client);
$ownerId = 'admin@duongvanba.com';
$x1 = new Google_Service_Classroom_Course(['name'=>'Math']);
$x1->setOwnerId($ownerId);
$r1 = $this->api->courses->create($x1);
$batch->add($r1, "a");
$x2 = new Google_Service_Classroom_Course(['name'=>'Geography']);
$x2->setOwnerId($ownerId);
$r2 = $this->api->courses->create($x2);
$batch->add($r2, "b");
$results = $batch->execute();
var_dump($results);
$client->setUseBatch(false);
}
}
?>
当我使用 Google Calendar API 进行批量请求时,一切正常。但使用 Classroom API 时,我收到的结果
object(Google_Service_Exception)#209 (8) {
["errors":protected]=>
NULL
["message":protected]=>
string(9) "Not Found"
["string":"Exception":private]=>
string(0) ""
["code":protected]=>
int(404)
["file":protected]=>
string(71) "/home/ubuntu/workspace/vendor/google/apiclient/src/Google/Http/REST.php"
["line":protected]=>
int(118)
["trace":"Exception":private]=>
array(51) {
[0]=>
array(6) {
["file"]=>
string(72) "/home/ubuntu/workspace/vendor/google/apiclient/src/Google/Http/Batch.php"
["line"]=>
int(172)
["function"]=>
string(18) "decodeHttpResponse"
["class"]=>
string(16) "Google_Http_REST"
["type"]=>
string(2) "::"
["args"]=>
array(2) {
[0]=>
object(GuzzleHttp\Psr7\Response)#226 (6) {
["reasonPhrase":"GuzzleHttp\Psr7\Response":private]=>
string(9) "Not Found"
["statusCode":"GuzzleHttp\Psr7\Response":private]=>
int(404)
["headers":"GuzzleHttp\Psr7\Response":private]=>
array(5) {
["content-type"]=>
array(1) {
[0]=>
string(24) "text/html; charset=UTF-8"
}
["date"]=>
array(1) {
[0]=>
string(29) "Fri, 24 Feb 2017 03:18:58 GMT"
}
["expires"]=>
array(1) {
[0]=>
string(29) "Fri, 24 Feb 2017 03:18:58 GMT"
}
["cache-control"]=>
array(1) {
[0]=>
string(18) "private, max-age=0"
}
["content-length"]=>
array(1) {
[0]=>
string(1) "9"
}
}
["headerNames":"GuzzleHttp\Psr7\Response":private]=>
array(5) {
["content-type"]=>
string(12) "content-type"
["date"]=>
string(4) "date"
["expires"]=>
string(7) "expires"
["cache-control"]=>
string(13) "cache-control"
["content-length"]=>
string(14) "content-length"
}
["protocol":"GuzzleHttp\Psr7\Response":private]=>
string(3) "1.1"
["stream":"GuzzleHttp\Psr7\Response":private]=>
object(GuzzleHttp\Psr7\Stream)#195 (7) {
["stream":"GuzzleHttp\Psr7\Stream":private]=>
resource(21) of type (stream)
["size":"GuzzleHttp\Psr7\Stream":private]=>
NULL
["seekable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["readable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["writable":"GuzzleHttp\Psr7\Stream":private]=>
bool(true)
["uri":"GuzzleHttp\Psr7\Stream":private]=>
string(10) "php://temp"
["customMetadata":"GuzzleHttp\Psr7\Stream":private]=>
array(0) {
}
}
}
.....
我应该怎么办 :(
作者:黑洞官方问答小能手
链接:http://www.phpheidong.com/blog/article/554226/913656fd7646338276dc/
来源:php黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 php黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-4
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!