Update POC

This commit is contained in:
Vincent BRIDIER 2023-04-11 10:43:05 +02:00
parent 087562bda1
commit 6eae213a18
No known key found for this signature in database
GPG key ID: 8571BFA20420D512
4 changed files with 21 additions and 9 deletions

View file

@ -10,6 +10,7 @@ use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Enums\ExcludeTypeEnum;
use Exception;
class InstaGetTopMediasJob implements ShouldQueue
{
@ -107,7 +108,11 @@ class InstaGetTopMediasJob implements ShouldQueue
*/
public function handle(int $count = 0, array $params = [])
{
$json = $this->callApi($params);
try {
$json = $this->callApi($params);
} catch (\Exception $e) {
// TODO : handle exception
}//end try
foreach ($json->data as $ig_media) {
if ($count < $this->nb_medias) {
if ($this->excludePosts->where('value', $ig_media->id)->isNotEmpty()) {
@ -123,7 +128,9 @@ class InstaGetTopMediasJob implements ShouldQueue
'permalink' => $ig_media->permalink,
'timestamp' => $ig_media->timestamp,
'like_count' => isset($ig_media->like_count) ? $ig_media->like_count : null,
'comments_count' => $ig_media->comments_count
'comments_count' => $ig_media->comments_count,
'username' => $username,
'caption' => $ig_media->caption,
];
$media = new InstaMedia();
@ -178,10 +185,10 @@ class InstaGetTopMediasJob implements ShouldQueue
if ($status === 200) {
return \json_decode($res->getBody());
} else {
\dd($res->getBody());
throw new \Exception($res->getBody());
}
} catch (\GuzzleHttp\Exception\ClientException $e) {
echo $e->getMessage();
throw new \Exception($e);
} //end try
}
@ -217,10 +224,10 @@ class InstaGetTopMediasJob implements ShouldQueue
}
}
} else {
\dd($res->getBody());
throw new \Exception($res->getBody());
}
} catch (\GuzzleHttp\Exception\ClientException $e) {
echo $e->getMessage();
throw new \Exception($e);
} //end try
}
}

View file

@ -25,6 +25,8 @@ class InstaMedia extends Model
'permalink',
'timestamp',
'like_count',
'comments_count'
'comments_count',
'username',
'caption'
];
}

View file

@ -45,13 +45,14 @@ return [
"like_count",
"comments_count",
"permalink",
"timestamp"
"timestamp",
"caption"
])
),
'ig_hashtag_id' => env('FACEBOOK_GRAPH_ENDPOINT_IG_TOPMEDIA_IGHASHTAGID'),
'user_id' => env('FACEBOOK_GRAPH_ENDPOINT_IG_TOPMEDIA_USERID'),
'limit' => env('FACEBOOK_GRAPH_ENDPOINT_IG_TOPMEDIA_LIMIT', 25),
'nb_medias' => env('FACEBOOK_GRAPH_ENDPOINT_IG_TOPMEDIA_NBMEDIAS', 25),
'nb_medias' => env('FACEBOOK_GRAPH_ENDPOINT_IG_TOPMEDIA_NBMEDIAS', 30),
]
]
]

View file

@ -21,6 +21,8 @@ return new class extends Migration
$table->string("timestamp");
$table->bigInteger("comments_count");
$table->bigInteger("like_count")->nullable();
$table->string('username');
$table->text('caption');
$table->timestamps();
});
}