How to access Restricted audio files in Google Drive API to play them in AVPlayer (Swift 5)

Viewed 272

In my app I want to be able to play audio files from Google Drive. I do it like this:

import AVKit

class MyVC: UIViewController {
...
var player: AVPlayer!
...
private func playTrack() {
   let url = URL(string: "https://drive.google.com/uc?export=open&id=XXXXX" //where XXXXX is an item id
   let playerItem: AVPlayerItem = AVPlayerItem(url: url!)
   player = AVPlayer(playerItem: playerItem)
   player!.play()
   }
}

But it only works with files for which I have previously enabled "Anyone with the link" access in Google Drive. access

But I'd like to be able to play files with Restricted access (which is set by default in Google Drive). To connect my application to Google Drive API I use API Key and OAuth 2.0 Client ID. I request the user for all Scopes that are available to an unverified application. This way I can get a list of the user's files and also download them. scope1 scope2

I know that there are applications that do not require the audio file to have "Anyone with the" access. I tested this on my audio files in Google Drive: this application plays the file with "Restricted" access easily, but my application doesn't. How can I solve this problem?

0 Answers
Related