need your help on uploading a zip file to google drive without authenticating it manually using my browser so that I can schedule the backup automatically.
My authentication and uploading code is as follows :
    $client = new Google_Client();
    $client->setClientId('clientid');
     $client->setClientSecret('clientsecret');
     $client->setAccessType("offline");
$client->setRedirectUri('http://localhost:60/pathtofile.php');
$client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
session_start();
if (isset($_GET['code']) || (isset($_SESSION['access_token']) && $_SESSION['access_token'])) {
    if (isset($_GET['code'])) {
        $client->authenticate($_GET['code']);
        $_SESSION['access_token'] = $client->getAccessToken();
    } else
        $client->setAccessToken($_SESSION['access_token']);
    $service = new Google_Service_Drive($client);
    //Insert a file
    $file = new Google_Service_Drive_DriveFile();
    //$file->setName(uniqid().'.zip');
    $file->setName($zipName . '.zip');
    $file->setDescription('Testing document ZIP backups');
    $file->setMimeType('application/zip');
    $data = file_get_contents($zipPath = $publicPath . '\\removedorgname\\backups\\' . $zipName . '.zip');
    $createdFile = $service->files->create($file, array(
          'data' => $data,
          'mimeType' => 'application/zip',
          'uploadType' => 'multipart'
        ));
    print_r($createdFile);
} else {
    $authUrl = $client->createAuthUrl();
    header('Location: ' . $authUrl);
    exit();
}
The problem i'm facing is that it asks me to manually sign in to the google account. I have researched this concept of a refresh token but don't understand how to implement it.
