I’m working on an Android app and need some help with Google Drive integration. When users perform a specific action in my app, I want to fetch certain files from a particular Google Drive account (like [email protected]) that contains app-related data.
I’ve been looking into the Google Drive API v2 but I’m not sure how to target a specific account rather than the currently logged in user’s account. The files I need to access are stored in this dedicated account that my app should connect to.
Can this be accomplished with the Drive API? If someone has experience with this kind of setup, I would really appreciate some guidance or code examples to get me started.
I hit this same issue last year and went with domain-wide delegation - worked great for us. You create a service account and enable domain-wide delegation in the Google Workspace admin console. Then your app can impersonate the target account programmatically. The big difference from regular service accounts? You don’t have to manually share every single file - your service account gets authorized to act as that specific user. One catch though - the target account needs to be part of a Google Workspace domain, which might not work for your setup. You’ll need to set up the right scopes and use the account email in your API calls.
To achieve access to a specific Google Drive account using API v2 in your Android app, you will need to implement service account authentication rather than relying on user authentication. Begin by creating a service account in the Google Cloud Console and grant it access to the files or folders in the target Drive account ([email protected]) by sharing them with your service account’s email. This approach allows your app to authenticate using the credentials from a JSON key file, circumventing any user login prompts. This way, no matter who uses your app, it will consistently access the same Drive account. Just ensure the service account has the necessary permissions and manage mobile authentication appropriately.
you could also use oauth2 with a fixed refresh token for that account. just authenticate once with [email protected], store the refresh token somewhere safe, then grab access tokens whenever you need them. it’s simpler than service accounts but riskier if someone gets hold of ur token.