我想在我的应用程序中连接Google Drive API,以显示用户文件列表并能够将它们下载到设备上。我正在遵循这个示例集成Google Drive到iOS应用程序。
我连接了Google SDK并成功授权了用户。但是无论如何都无法获取其文件列表。我不断收到以下错误消息:
"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
我多次检查了我的应用程序和Google Console中的设置,按照步骤进行了一切,但仍然无法解决此问题。是否有人遇到过相同的问题?
我的代码和屏幕截图:
我连接了Google SDK并成功授权了用户。但是无论如何都无法获取其文件列表。我不断收到以下错误消息:
"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
我多次检查了我的应用程序和Google Console中的设置,按照步骤进行了一切,但仍然无法解决此问题。是否有人遇到过相同的问题?
我的代码和屏幕截图:
//class AppDelegate...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GIDSignIn.sharedInstance().clientID = "Me client ID"
return true
}
//class myVC: GIDSignInDelegate...
override func viewDidLoad() {
super.viewDidLoad()
GIDSignIn.sharedInstance().presentingViewController = self
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().scopes = [kGTLRAuthScopeDrive]
GIDSignIn.sharedInstance().restorePreviousSignIn()
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
withError error: Error!) {
if let error = error {
print("Google autorization error: \(error.localizedDescription)")
return
}
guard let token = user.authentication.accessToken else { return }
SourceAuthorizationStateManager.shared.addAuthorizedSource(.googleDrive)
let fullName = user.profile.name
print("Google authorization successful. User name: \(fullName ?? "Error: no user name")\nUser token: \(token)")
}
//class GoogleDriveFileListSource...
private var fileListTicket: GTLRServiceTicket?
var files: [FileModelProtocol] {
guard let files = fileList?.files else { return [] }
return files.map { GoogleDriveFileModel($0) }
}
lazy var driveService: GTLRDriveService = {
let service = GTLRDriveService()
service.shouldFetchNextPages = true
service.isRetryEnabled = true
return service
}()
func fetchFileList(path: String?, _ completion: @escaping () -> Void) {
let query = GTLRDriveQuery_FilesList.query()
query.fields = "kind,nextPageToken,files(mimeType,id,kind,name,webViewLink,thumbnailLink,trashed)"
fileListTicket = driveService.executeQuery(query,
completionHandler: { [weak self] (_, resultObject, error) in
if let error = error {
debugPrint("driveService.executeQuery error: \(error.localizedDescription)")
return
}
guard let self = self,
let fileList = resultObject as? GTLRDrive_FileList else { return }
self.fileList = fileList
self.fileListTicket = nil
completion()
})
}