本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

无法在 Google Classroom API 中使用批处理请求

发布于2024-10-31 15:35     阅读(169)     评论(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黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

5 0
收藏该文
已收藏

评论内容:(最多支持255个字符)