From 918b444cb9770b9397039e7741280d5ad1b998da Mon Sep 17 00:00:00 2001 From: philipp lang Date: Mon, 15 Aug 2022 22:02:55 +0200 Subject: [PATCH] fixed: dont sync instagram posts without captions --- classes/InstagramService.php | 6 +++++- formwidgets/InstagramLogin.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/classes/InstagramService.php b/classes/InstagramService.php index b48932c..9ef450b 100644 --- a/classes/InstagramService.php +++ b/classes/InstagramService.php @@ -90,8 +90,12 @@ class InstagramService extends SocialService { $posts = json_decode((string) $response->getBody(), true)['data']; foreach ($posts as $post) { + if (!data_get($post, 'caption')) { + continue; + } + yield [ - 'message' => $post['caption'], + 'message' => data_get($post, 'caption', ''), 'remote_id' => $post['id'], 'href' => $post['permalink'], 'created_at' => Carbon::parse($post['timestamp']), diff --git a/formwidgets/InstagramLogin.php b/formwidgets/InstagramLogin.php index b0fddd3..81d403f 100644 --- a/formwidgets/InstagramLogin.php +++ b/formwidgets/InstagramLogin.php @@ -64,7 +64,7 @@ class InstagramLogin extends FormWidgetBase { $me = app(InstagramService::class)->me($accessToken); - Page::create([ + Page::updateOrCreate(['remote_id' => $me['id']], [ 'access_token' => $accessToken, 'type' => app(InstagramService::class)->getType(), 'name' => $me['username'],