类 stdClass 的对象无法转换为字符串 Eventbrite API


Object of class stdClass could not be converted to string Eventbrite API

我正在尝试将站点从旧的Eventbrite API升级到新的。这个php代码在旧的代码上运行良好。

我正在尝试将事件从 Eventbrite 保存到我们自己网站上的事件部分。

我从事件中得到事件没有问题:

$json = file_get_contents('https://www.eventbriteapi.com/v3/events/'.$id.'?token=evbsecrettoken');
$event = json_decode($json);

然后我尝试将其保存到我们的网站,使用我知道可以从我们的后端工作的保存功能

$eventId = $this->config->DS->saveEvent('new',
                    $event->name->text,
                    $event->description,
                    $countryId,
                    $cityId,
                    $venueId,
                    $event->start->local,
                    '',
                    0,
                    0,
                    $image,
                    $_SESSION['admin']['user_id']);

保存事件函数看起来像

public function saveEvent($id, $title, $body, $country, $city, $venue, $date, $cost, $ticker, $active, $image, $userId) {
    if($id == 'new'){
        $slug = $this->getAvailableSlugByTable('event', $title);
        $eventId = $this->addEvent($userId, $country, $city, $venue, $title, $date, $cost, $body, $image, $slug, $ticker, $active);
        return $eventId;

添加事件看起来像

 public function addEvent($userId, $country, $city, $venue, $title, $date, $cost, $text, $image, $slug, $ticker = 0, $active = 0){
    $this->dbHandler->DbQuery('INSERT event SET user_id = ?, country_id = ?, city_id = ?, venue_id = ?, event_title = ?, event_date = ?, event_cost = ?, event_text = ?, event_image = ?, event_slug = ?, event_ticker = ?, event_active = ?', Array($userId, $country, $city, $venue, $title, $date, $cost, $text, $image, $slug, $ticker, $active));
    $eventId = $this->dbHandler->lastInsertId();
    // add ticker if needed
    if($ticker){
        $this->addTicker('event', $title, $slug, $text, $image, 'events', $eventId, $userId, 0);
    }
    return $eventId;
}

但是我收到"可捕获的致命错误:类 stdClass 的对象无法转换为字符串"错误,堆栈跟踪如下所示:

[03-Feb-2016 21:11:13 UTC] PHP   7. Admin_Data_Source->saveEvent() /home/ubuntu/workspace/admin/modules/eventbrite.php:94
[03-Feb-2016 21:11:13 UTC] PHP   8. Site_Data_Source->addEvent() /home/ubuntu/workspace/lib/persistence/adminDataSource.php:368
[03-Feb-2016 21:11:13 UTC] PHP   9. DBhandler->DbQuery() /home/ubuntu/workspace/lib/persistence/siteDataSource.php:553
[03-Feb-2016 21:11:13 UTC] PHP  10. PDOStatement->execute() /home/ubuntu/workspace/lib/dbHandler/dbHandler.php:88

知道我做错了什么吗?我不知道哪个类正在转换。非常感谢任何帮助,谢谢!

似乎您的一个变量不是字符串。

在 addEvent 函数中,我会对每个函数参数进行var_dump并检查其类型。图像可能是一个对象,而不是您所期望的字符串。