【发布时间】:2020-09-16 18:31:29
【问题描述】:
我想在我的应用程序中连接到 Google Drive API,以便显示用户文件列表并能够将它们下载到设备。我正在关注这个示例Integrate Google Drive to iOS app
我已连接 Google SDK 并成功授权用户。但是我无法以任何方式获取其文件列表。我不断收到以下错误:
“已超过未经验证使用的每日限制。继续使用需要注册。”
我在 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()
})
}
【问题讨论】:
-
kGTLRAuthScopeDrive 的值是多少
标签: ios swift google-drive-api