cleaner login process
This commit is contained in:
parent
dee2522676
commit
920c8932a0
3 changed files with 47 additions and 28 deletions
|
@ -1,8 +1,11 @@
|
|||
<?php
|
||||
|
||||
|
||||
// === Example use ===
|
||||
#addVideoToFediList('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
|
||||
|
||||
require_once('utils.php');
|
||||
|
||||
function isYouTubeLink($url) {
|
||||
return preg_match('#^(https?://)?(www\.)?(youtube\.com/watch\?v=|youtu\.be/)[a-zA-Z0-9_-]{11}#', $url);
|
||||
}
|
||||
|
@ -39,14 +42,19 @@ function addVideoToFediList($videoUrl) {
|
|||
//print_r($token);
|
||||
|
||||
// === Refresh token if expired ===
|
||||
|
||||
// Don't let it expire, refresh if we have less than 15 minutes left
|
||||
// Google Tokens usually last 60 min, so more ore less around 45min we get a new one
|
||||
$refreshSecondMargin = 15*60;
|
||||
|
||||
if (isset($token['expires_at'])) {
|
||||
$secondsLeft = $token['expires_at'] - time();
|
||||
if ($secondsLeft > 0) {
|
||||
if ($secondsLeft > $refreshSecondMargin) {
|
||||
$minutes = floor($secondsLeft / 60);
|
||||
$seconds = $secondsLeft % 60;
|
||||
echo "⏳ Token expires in $minutes minutes and $seconds seconds.\n";
|
||||
} else {
|
||||
echo "🔄 Access token expired. Refreshing...\n";
|
||||
echo "🔄 Access token expired or will expire in less than $refreshSecondMargin seconds. (Seconds Left: $secondsLeft). Refreshing...\n";
|
||||
|
||||
$refreshResponse = curlPost('https://oauth2.googleapis.com/token', [
|
||||
'client_id' => $clientId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue