【问题标题】:Google_Activity must be an instance of Google_ActivityObjectGoogle_Activity 必须是 Google_ActivityObject 的一个实例
【发布时间】:2017-03-20 02:16:52
【问题描述】:

我不知道这是什么错误。我可能认为在谷歌 PHP 客户端库中也有人可以帮助解决这个问题。

这是我的代码:

$this->client->refreshToken($con[0]->secret);
$newtoken = $this->client->getAccessToken();
$this->client->setAccessToken($newtoken);

$activityAccess = new Google_Acl();
$activityAccess->setDomainRestricted(true);

$object = new Google_ActivityObject();
$originalContent = $object->setOriginalContent('Happy me');
$originalContent = $object->setContent('Happy me');
$originalContent = $object->setObjectType('domain');

$body = explode(".", $args["post"]);
$activity = new Google_Activity();
$postBody = $activity->setTitle($body[0]);
$postBody = $activity->setVerb('post');
$postBody = $activity->setKind('plus#activity');
$postBody = $activity->setObject($originalContent);
$postBody = $activity->setAccess($activityAccess);

$data = $this->connect->activities->insert('me', $postBody);

这会产生以下错误。我不知道错误的确切含义。

A PHP Error was encountered
Severity: 4096
Message:  Argument 1 passed to Google_Activity::setObject() must be an instance of Google_ActivityObject , null given, called in
/home/socialsu/public_html/application/autopost/Google_plus.php on
line 179 and  defined
Filename: contrib/Google_PlusDomainsServices.php
Line Number: 635
A PHP Error was encountered
Severity: 4096
Message:  Argument 2 passed to Google_ActivitiesServiceResource::insert() must be an instance of Google_Activity, null given, called in /home/socialsu/public_html/application/autopost/Google_plus.php on line 182 and  defined
Filename: contrib/Google_PlusDomainsServices.php
Line Number: 54
A PHP Error was encountered
Severity: Notice
Message:  Undefined index: type
Filename: io/Google_REST.php
Line Number: 98
A PHP Error was encountered
Severity: Notice
Message:  Undefined index: value
Filename: io/Google_REST.php
Line Number: 109

【问题讨论】:

    标签: php google-api-php-client google-domain-api


    【解决方案1】:

    这里的错误是没有正确构建活动对象,因此出现错误“must be an instance of Google_Activity”。您可以通过多种方式构建活动对象,以将其作为评论插入到您的 G Suite Google Plus 个人资料中。以下面的方法为例。

    $service = new Google_Service_PlusDomains($client);
    
    $activity = new Google_Service_PlusDomains_Activity(
       array(
          'access' => array(
              'items' => array(
                  'type' => 'domain'
              ),
              'domainRestricted' => true
          ),
          'verb' => 'post',
          'object' => array(
              'originalContent' => "Post using Google API PHP Client Library!" 
          ), 
       )
    );
    
    $newActivity = $service->activities->insert("me", $activity);    
    
    var_dump($newActivity);
    

    reference documentation 解释了对象必须具有的必需和可选属性。我强烈建议您使用上面解释的数组来构建对象。那应该使它起作用。我希望这些信息对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多