victorpacheco3107
victorpacheco3107

Reputation: 862

Upload file to google drive in java without OAuth

I want upload a file to my account in google drive. This process should be without human intervention. Is there any way to upload a file in my google drive using the google drive api providing my user and my password?

What I've done so far:

When I run the code the result is ok, I get file's id and the alternate link, but the file not load to my account. I paste the alternate link in a browser but I not have permission.

Where is the file you just uploaded? What should I change to indicate that up to my account drive? Where should I add my username and password to be associated with my drive? What should I do to the file to become public?

Thank you very much for all your attention. I wish they can help me.

Upvotes: 1

Views: 1977

Answers (2)

Chandan Reddy
Chandan Reddy

Reputation: 499

You are uploading the file into your service account. If you need to access the file, it must be shared with your email. use the following method to share the file with your email.

 public static void shareFileOrFolder(Drive service, File file)
        throws IOException {
    Permission newPermission = new Permission();

    newPermission.setEmailAddress("[email protected]");
    newPermission.setValue("[email protected]");
    newPermission.setType("user");
    newPermission.setRole("writer");
    service.permissions().insert(file.getId(), newPermission).execute();
}

Upvotes: 1

Dan McGrath
Dan McGrath

Reputation: 42018

You will also need to set a parent on the item, such as 'root' so that they appear someone in the 'My Drive' space. 'root' as a parent is 'My Drive' in the UI.

Use Search in the Drive UI to confirm and you should find they have been uploaded, but are currently in a state called 'unparented' since your code doesn't add a parent.

Upvotes: 1

Related Questions