With Service account, Not getting any files / folder list with PHP - google-drive-api

What will extra setting to get files / folder from google drive API with service account? Currently getting empty results.
Same code working with credential web scope with client id and secrets key but not with service account.

When you use a web client. It pops up and requests authorizaiton. In this way a user is granting your application access to their data. So a file.list will return the files on the users google drive account.
The same thing is happening with your service account. Only service accounts are pre authorized. Your file.list is returning no files becouse the service account doesnt have acess to any files yet. You see it has its own drive account.
Options.
Upload files to the service accounts drive account.
open your credetials.json file. Look for the service account email address. Take that address and share a directory or file on your personal drive account with the service account.
Now do a file.list. It should have files.

Related

Can I merge Web-Client Account with Service Account?

I have an app setup with the Web-Client structure, using it as a kind of server manager for many users. They can't access the account but only some folders, as I do all the authorization steps by code. I chose this kind of account in Drive API so I could upload big files, as service accounts were very limited. But now there are some files that can be uploaded through the Web drive.google.com domain, and I need to own this files that the e-mails from my same domain have uploaded. So I was thinking if it was possible to have a service account to change permissions only, and do all the file uploads though the Web-Client Account within the same project and email? Thanks.

Box.com super account to get all the box.com users folders and files

I have a user cases to get all the box.com users folders and files through one single box.com super service account authentication without each single user's credentials like google drive did. Is it a way to do that through box.com api?
Eric
Yes you can if you have an enterprise account. You can use On-Behalf-Of feature in V2 API and can see other managed users' files and folders by authenticating as enterprise admin. Box will have to enable the On-Behalf-Of feature before you try this in your app.

Google Drive SDK: To copy files from a user to another user via Domain Super Administrator access right

Say, I am a Domain Super Administrator. And, there are User A (source - files to be copied from) and User B (destination - files to be copied to). Is there any Google Drive SDK API available for this feature?
When I read this: https://developers.google.com/drive/v2/reference/files/copy, this API allows only to copy into my own Google Drive.
Please help. Thanks.
Use domain-wide delegation to impersonate each user https://developers.google.com/drive/delegation.
Authenticate as source user and share file with target user https://developers.google.com/drive/v2/reference/permissions/insert
Authenticate as target user and copy source file to produce target copy of file owned by target user https://developers.google.com/drive/v2/reference/files/copy

Google Drive upload from webserver

I'm trying to make a service that runs on a webserver and can upload files to Google Drive,
so that people can sync the files to local-drive using the Google desktop application.
So I tried the Drive API but it requires a webbrowser to authenticate.
This would be a possibility, but I don't know to get the access token programmically.
Even if I had the access token, I wouldn't know if it just works forever.. It seems to have an expire date?
I wouldn't want the service to suddenly not working, because the token has expired.
Than I learned about Service Account, and finally got it working, but it seems to have its own space that i can only access with the service account.
I don't know how to share the files from the service account to a regular account, as people need to sync it locally.
So a found a video about user impersonation, in which he showed a page about given access to a service account to impersonate another user.
But i don't know where to find this page.
Looking at: http://support.google.com/a/bin/answer.py?hl=en&answer=162106&topic=2759255&ctx=topic
It says it's in Advanced Tools > Manage third party OAuth client access (under the Authentication section).
But where is the Authentication section? Do I need to create a Google App to do this?
The question is: How upload files programmically to Google Drive without any user intervention, so that they can be synced locally with the drive desktop-application.

How to transfer File Ownership for a Document which admin doesn't own?

Use Case
As admin service account, transfer Document Ownership using the Google Docs API, similar to the built in cPanel "Advanced Tools" -> "Document ownership transfer"
Constraints
APIs are being invoked in context of a Google Apps admin service account rather than the end-user account since APIs are being invoked from Google Apps Script in Sites page
Authorization is OAuth 1.0 since this is what Apps Script supports
What works:
Transferring ownership of the admin service account's own files to another user's account as documented here
What is required:
Transfer ownership of another user's files, ideally without them sharing any permissions with the admin service account; if there's no other way of doing it, they could share edit permissions on the file with the admin service account.
Currently this returns a
" ServiceException - You do not have permission to share these item(s):"
What you're trying to do is possible by impersonating the user using the admin account. The documentation shows how to do this here.
Essentially, start by requesting the API URL with default replaced with the current owner's email address. The request must be made while authorized as the admin user, though.
https://docs.google.com/feeds/user#yourdomain.com/private/full/
Once that URL is requested, all feed URLs will be returned with that email already present. Then, simply change ownership as you would normally.