From dcdf95d1a5d1729faf1ef27e5772c219b75e5f97 Mon Sep 17 00:00:00 2001 From: Francisc Tar Date: Sat, 29 Feb 2020 09:47:01 +0100 Subject: [PATCH] decode widgets into an Object --- src/Google/GTrends.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Google/GTrends.php b/src/Google/GTrends.php index b22edf8..e20c37c 100644 --- a/src/Google/GTrends.php +++ b/src/Google/GTrends.php @@ -353,16 +353,16 @@ public function interestOverTime($kWord, $category=0, $time='now 4-H', $property $data = $this->_getData(self::GENERAL_ENDPOINT, 'GET', $payload); if ($data) { - $widgetsArray = Json\Json::decode(trim(substr($data, 4)), Json\Json::TYPE_ARRAY)['widgets']; + $widgets = Json\Json::decode(trim(substr($data, 4)), Json\Json::TYPE_OBJECT)->widgets; - foreach ($widgetsArray as $widget) { + foreach ($widgets as $widget) { - if ($widget['id'] == 'TIMESERIES') { + if ($widget->id == 'TIMESERIES') { $interestOverTimePayload['hl'] = $this->options['hl']; $interestOverTimePayload['tz'] = $this->options['tz']; - $interestOverTimePayload['req'] = Json\Json::encode($widget['request']); - $interestOverTimePayload['token'] = $widget['token']; + $interestOverTimePayload['req'] = Json\Json::encode($widget->request); + $interestOverTimePayload['token'] = $widget->token; $data = $this->_getData(self::INTEREST_OVER_TIME_ENDPOINT, 'GET', $interestOverTimePayload); if ($data) {