I am getting the error:
The user does not have sufficient permissions for this file
when trying to show files from Google Drive.
func handleSignInButton() {
// let signInConfig = GIDConfiguration.init(clientID: "356464518615-9meu8jn6nn2a0gu2415ar8cn01ml8b4u.apps.googleusercontent.com")
guard let presentingViewController = (UIApplication.shared.connectedScenes.first
as? UIWindowScene)?.windows.first?.rootViewController else {return}
GIDSignIn.sharedInstance.signIn(withPresenting: presentingViewController) { user, error in
guard let result = user else {
// Inspect error
return
}
let driveScope = "https://www.googleapis.com/auth/drive.readonly"
let fileScope = "https://www.googleapis.com/auth/drive.file"
let grantedScopes = GIDGoogleUser().grantedScopes
if grantedScopes == nil || !grantedScopes!.contains(driveScope) || !grantedScopes!.contains(fileScope){
// Request additional Drive scope.
let additionalScopes = [driveScope, fileScope]
guard let currentUser = GIDSignIn.sharedInstance.currentUser else {
return ; /* Not signed in. */
}
currentUser.addScopes(additionalScopes, presenting: presentingViewController) { signInResult, error in
guard error == nil else { return }
guard signInResult != nil else { return }
// Check if the user granted access to the scopes you requested.
}
openAllFilesOnGoogleDrive()
}
}
}
func openAllFilesOnGoogleDrive() {
let service = GTLRDriveService()
service.apiKey = "AIzaSyBYCmoxlaXj_HI8bTj1jlQTmJ2GI64ZP2Q"
let query = GTLRDriveQuery_FilesList.query()
query.spaces = "drive"
query.corpora = "user"
query.fields = "files(id,name,modifiedTime,size)"
let audioOrVideoFiles = "mimeType contains 'audio/' or mimeType contains 'video/'"
query.q = "\(audioOrVideoFiles)"
service.executeQuery(query) { _, result, error in
if let error = error {
// Handle error
print("Error retrieving file list: \(error.localizedDescription)")
return
}
if let fileList = result as? GTLRDrive_FileList {
for file in fileList.files ?? [] {
fileListArray.append(file)
print("fileListArray \(fileListArray)")
print("File name: \(file.name ?? "")")
print("File ID: \(file.identifier ?? "")")
print("File Size: \(file.size ?? 0)")
print("--------------------")
}
}
}
}
I have given full access and transferred permission from private to everyone