How to specify application name for GTLRDriveService to use drive.file scope
R4N opened this issue · comments
Our application currently uses kGTLRAuthScopeDrive
scope for uploading/downloading files. We'd like to transition over to the more restrictive kGTLRAuthScopeDriveFile
scope. Our app is on multiple platforms which have different client ids for communicating with Google Drive. If I understand correctly, we'll need to specify the same application name on the service when setting it up so that each platform will be able to access files uploaded by other platforms.
When looking at the sample code for uploading a file here: https://developers.google.com/drive/api/guides/manage-uploads#java the example code for Java looks like it allows you to specify an application name:
// Build a new authorized API client service.
Drive service = new Drive.Builder(new NetHttpTransport(),
GsonFactory.getDefaultInstance(),
requestInitializer)
.setApplicationName("Drive samples")
.build();
I tried looking at the header for GTLRDriveService (and it's superclass GTLRService) but couldn't find any properties for the application name.
I also took a look at the DriveSample example provided with the library, but it uses the less restrictive scope (but does have a comment above it about using the more restrictive scope):
// Applications that only need to access files created by this app should
// use the kGTLRAuthScopeDriveFile scope.
NSArray<NSString *> *scopes = @[ kGTLRAuthScopeDrive, OIDScopeEmail ];
Is my understanding correct that we somehow need to specify an application name on the GTLRDriveService (or somewhere else) to be able to access files uploaded by other client ids (but associated with the same application) when using the more restrictive drive.files scope? And if so, how/where do we specify it?
Looking at the java docs on https://googleapis.dev/java/google-api-client/latest/index.html, setApplicationName
is documented as
public AbstractGoogleClient.Builder setApplicationName([String] applicationName)Sets the application name to be used in the UserAgent header of each request or null for none.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
So you likely get the same behaviors via the GTLR properties for userAgent controlling and/on on the GTMSessionFetcherService
that your GTLRService
is using.
Thanks for the fast response. I should have looked at the java docs, sorry about that. I'll give setting the userAgent on GTMSessionFetcher
associated with the GTLRService
a go, that does look like the appropriate property to set. Appreciate it!