function insertPermission($fileId, $value, $type, $role) { $wpdm_google_drive = maybe_unserialize(get_option('__wpdm_google_drive', array())); $client = new Google_Client(); $client->setClientId($wpdm_google_drive['client_id']); $client->setClientSecret($wpdm_google_drive['client_secret']); $client->addScope(Google_Service_Drive::DRIVE); $client->addScope(Google_Service_Drive::DRIVE_FILE); $client->addScope(Google_Service_Drive::DRIVE_READONLY); $client->addScope(Google_Service_Drive::DRIVE_APPDATA); $client->addScope(Google_Service_Drive::DRIVE_APPS_READONLY); $client->addScope(Google_Service_Drive::DRIVE_METADATA_READONLY); $client->setRedirectUri(admin_url('/?page=wpdm-google-drive')); $access_token = isset($_SESSION['wpdmgd_access_token']) ? $_SESSION['wpdmgd_access_token'] : ''; $client->setAccessToken($access_token); $service = new Google_Service_Drive($client); $newPermission = new Google_Service_Drive_Permission(); $newPermission->setValue($value); $newPermission->setId($fileId); $newPermission->setType($type); $newPermission->setRole($role); try { $ret = $service->permissions->insert($fileId, $newPermission); } catch (Exception $e) { $ret = "An error occurred: " . $e->getMessage(); } return $ret; }