2016-02-03 258 views
0

我正在嘗試將網站從舊的Eventbrite API升級到新的網站。這個PHP代碼在舊版本上運行良好。stdClass類的對象無法轉換爲字符串Eventbrite API

我試圖將事件從Eventbrite保存到我們自己網站上的事件部分。

我從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']); 

的saveEvent函數看起來像

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; 

的addEvent看起來像

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 

任何想法,我做錯了什麼?我不知道哪個班正在轉換。任何幫助非常感謝,謝謝!

回答

0

看起來好像你的一個變量不是字符串。

在addEvent函數中,我會對每個函數參數做一個var_dump並檢查它的類型。這是可能的圖像是一個對象,而不是你所期望的字符串。

相關問題