Hey everyone! I’m having trouble getting my Google Drive files to show up in my Swift app. The login part works fine, but when I try to get my file list, I keep getting this error:
Error Domain=com.google.GTLRErrorObjectDomain Code=403 "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
I’ve set up everything according to the docs, but no luck. Here’s what my code looks like:
func viewDidLoad() {
// Set up Google Sign-In
setupGoogleSignIn()
// Add sign-in button
let signInButton = createSignInButton()
view.addSubview(signInButton)
}
func onSuccessfulSignIn(user: GIDGoogleUser) {
print("Logged in as: \(user.profile.email ?? "")")
// Try to fetch files
let fileQuery = createFileListQuery()
driveService.executeQuery(fileQuery, completion: handleFileQueryResult)
}
func handleFileQueryResult(files: [GTLRDrive_File]?, error: Error?) {
if let error = error {
print("Error fetching files: \(error)")
return
}
if let files = files, !files.isEmpty {
print("Found \(files.count) files:")
files.forEach { print($0.name ?? "Unnamed file") }
} else {
print("No files found")
}
}
Any ideas what I’m doing wrong? The email prints correctly, so I know I’m logged in. But right after that, boom - error city. Help!
I encountered this problem as well. The error message suggests you’re hitting API limits for unauthenticated requests, which is odd since you’re logged in. Double-check your API credentials in the Google Cloud Console. Ensure you’re using the correct client ID and that it’s properly configured for iOS. Also, verify that you’ve added the necessary Drive API scopes to your GIDConfiguration. If those check out, try implementing exponential backoff for API requests. Sometimes, temporary server issues can cause this error, and retrying with increasing delays can help. Lastly, monitor your API usage quotas in the Google Cloud Console to ensure you haven’t hit any limits.
I’ve dealt with this frustrating issue before. One thing that’s not immediately obvious is that you need to set up the GTLRDriveService with the user’s authentication. Try adding this after successful sign-in:
let auth = user.authentication
let service = GTLRDriveService()
service.authorizer = auth.fetcherAuthorizer()
Also, make sure you’re using the latest version of GoogleSignIn and GoogleAPIClientForREST pods. Older versions can cause weird authentication problems.
If that doesn’t work, double-check your Google Cloud Console settings. Sometimes the error message is misleading, and it’s actually a configuration issue on the backend. Make sure you’ve enabled the Drive API and that your OAuth consent screen is properly set up with the right scopes.
Lastly, if all else fails, try implementing a custom GTMFetcherAuthorizationProtocol. It’s a bit more work, but it gives you finer control over the auth process and can help diagnose where things are going wrong.
hey there flyingeagle, i had a similar issue. make sure you’ve enabled the drive api in your google cloud console and added the right scopes. also, check if your app is still in testing mode - google might be limiting access. if none of that works, try revoking and re-granting permissions. good luck!