Google Drive service account for my android app

736 views Asked by At

I want to use google drive to upload and download file directly from my Andriod app without any user interaction.I have followed google quick start page of drive api and it works correctly but thing is i want app to authenticate it self directly without asking user to select account it there any way that. I can enter username and pass directly during code. there are options like service account

when i google for this but no tutorial there are other tutorials with php and ruby but they are on browser i want it to be integrated with my app. So as soon as i open my app it should fetch file from google drive without any user need

any help or link to tutorial for andriod app will be helpful

1

There are 1 answers

0
ReyAnthonyRenacia On

You can follow the service account sample in this repository.

Here's a snippet which shows how to build service account credential.

HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
...

GoogleCredential credential = GoogleCredential.fromStream(new FileInputStream("MyProject-1234.json"))
    .createScoped(Collections.singleton(PlusScopes.PLUS_ME));
// Set up global Plus instance.
plus = new Plus.Builder(httpTransport, jsonFactory, credential)
    .setApplicationName(APPLICATION_NAME).build();