Code Monkey home page Code Monkey logo

google-drive-recursive-ownership's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-drive-recursive-ownership's Issues

Error : Consent is required to transfer ownership of a file to another user.

PS C:\Users\Clement\Documents\Mes-Documents\coding\google-drive-recursive-ownership\google-drive-recursive-ownership> python .\transfer.py "test transfer" *@gmail.com
Changing all files at path "test transfer" to owner "*@gmail.com"
Prefix: ['test transfer']
Use this link for authorization: https://accounts.google.com/o/oauth2/auth?client_id=****
Verification code: ****
User *@gmail.com is permission ID *.
Gathering file listings for prefix []...
Folder: test transfer ([], *)
Gathering file listings for prefix ['test transfer']...
File: empty (['test transfer'], *)
Item b'test transfer\\empty' needs ownership granted.
   Creating new ownership permissions.
An error occurred inserting ownership permissions: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files/1WAMRlwFeqj5urN2Bl6UhiLgdDzCYfJo98VIKtW5UbRY/permissions?emailMessage=Automated+recursive+transfer+of+ownership.&alt=json returned "Consent is required to transfer ownership of a file to another user.". Details: "[{'message': 'Consent is required to transfer ownership of a file to another user.', 'domain': 'global', 'reason': 'consentRequiredForOwnershipTransfer'}]">
Item b'test transfer' needs ownership granted.
   Creating new ownership permissions.
An error occurred inserting ownership permissions: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files/1LdEQ0-SFR59U15V5Rt9RNCtdEIdYqUIi/permissions?emailMessage=Automated+recursive+transfer+of+ownership.&alt=json returned "Consent is required to transfer ownership of a file to another user.". Details: "[{'message': 'Consent is required to transfer ownership of a file to another user.', 'domain': 'global', 'reason': 'consentRequiredForOwnershipTransfer'}]">

Granting edit rights to *@gmail.com doesn't fix the issue.

I'm trying give ownership acess from another @gmail.com account

Great Tool but

super usful tool.

But is there anyway when using a supr admin user you can change all the owners to 1 owner of a shared folder.

were using gsuite basic

wrong owner after script runs

Luckily I caught this early because I have 10,000's of files I was going to execute this on. By comparing the console output and using https://developers.google.com/drive/v2/reference/permissions/getIdForEmail, I can tell that the correct drive#permissionId is being obtained for the email provided in the command-line, but by looking at new owners in drive and activity for affected items, I've found that the wrong account is getting ownership.

I'm forking to investigate and possibly provide some output control options making this hard to use for me. I'll update here and/or submit a PR if I find anything conclusive.

Getting "Insufficient permissions for this file" - what is correct way to create client_secrets.json?

I am trying to use this tool, and so far I think it's pretty nifty. I am struggling with what I believe to be a client_secrets.json problem. When running transfer.py, it tries to update ownership permissions of a .jpg file, and fails with the below message:

An error occurred updating ownership permissions: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files/10-some_text/permissions/some_numbers?transferOwnership=true&alt=json returned "Insufficient permissions for this file">

Based on this Stack Overflow question, it seems I may have my client_secrets.json permissioning all wrong.

I see from within transfer.py it wants to use Drive API v2, and the OAuth2 scope https://www.googleapis.com/auth/drive.

Here is how I generated my client_secrets.json:

  1. Went to https://console.developers.google.com/
  2. Made a project
    • Project name: "xyz" (not the real name)
    • Project ID: went with autogenerated ID
    • Location: No organization
  3. Went to https://console.developers.google.com/apis/library
  4. Enabled Google Drive API
  5. Went to https://console.developers.google.com/apis/credentials/consent
  6. Made an OAuth consent screen
    • Application name: "abc" (not the real name)
    • Support email: my email
    • Left everything else as default
  7. Went to https://console.developers.google.com/apis/credentials/wizard
    • Which API? Google Drive API
    • Where? Other UI
    • What data? User data
  8. It took me to a "Create an OAuth 2.0 client ID" page
    • Name: test-client-id (not the real name)
  9. I hit the Download button --> downloaded client_id.json
{
    "installed": {
        "client_id": "some_number-some_text.apps.googleusercontent.com",
        "project_id": "xyz",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://oauth2.googleapis.com/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_secret": "some_secret",
        "redirect_uris": ["urn:ietf:wg:oauth:2.0:oob", "http://localhost"]
    }
}
  1. I copied that file contents over the previous client_secrets.json
  2. And I ran the transfer.py script and got the above warning

What am I doing wrong in generating the client_secrets.json? Can anyone advise?

Path treverse issue?

Hi,

I am unsure if it is a problem or not, I could not find a simple hint in the code.

If I use the X/Y path, It recursively changed:

  • X/Y/** - expected
  • X/Y - expected
  • X - unexpected

Is this intentional? I expected a change only in the subtree of leaf.

Thanks,
Alon

OOB authentication method deprecated

I'm having trouble getting a valid session. The error directs me to https://developers.google.com/identity/protocols/oauth2/resources/oob-migration which indicates that the token acquisition method is likely no longer valid for desktop clients.

flow.redirect_uri = oauth2client.client.OOB_CALLBACK_URN

It suggests switching to a loopback redirect uri https://developers.google.com/identity/protocols/oauth2/native-app#redirect-uri_loopback

This is awesome

This is an awesome library. Thank you for writing it.

Feel free to close this issue.

Use with G Suite Basic?

super usful tool.

But is there anyway when using a supr admin user you can change all the owners to 1 owner of a shared folder.

were using gsuite basic

wildcard?

Will a wildcard work in the path specification?

Only recurses 1 level

The script doesn't seem to crawl the entire directory structure but only changes ownership of the objects immediately within the shared folder.

Between this and the #19, it's hard to find usefulness in this script outside cases simple situations that are relatively quick to do manually via the web interface already.

hundreds of thousands of files...

Thanks for the tool. Not sure if it used to be faster, but it seems to be chunking along at 1-2 files per second. Perhaps a constraint on google's end. Nevertheless, i have about 360k files for which i need to change ownership.... I have a few instances running on different subfolders... but wondering if there's any other way of speeding this up? thanks again...

Great project! Thanks!

I don't know a better way to send you a message: this is a great project! Thanks very much.

invalid_clientUnauthorized

I am not sure how to modify the client secrets file. I simply changed the value for "client_secret" to some arbitrary string. When I execute the application I am encountering this error.

Changing all files at path "\apardo\non_financial\software_licenses" to owner "[email protected]"
Prefix: ['', 'apardo', 'non_financial', 'software_licenses']
Use this link for authorization: https://accounts.google.com/o/oauth2/auth?clien
t_id=665081966568.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoaut
h%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&access_type=
offline&response_type=code
Verification code: 4/tgEQ4-DZTu_acFEc6vUljqjgK8cRrPAhhMLTEIELv_zIsSF_omuEntw
Traceback (most recent call last):
File "transfer.py", line 133, in
service = get_drive_service()
File "transfer.py", line 23, in get_drive_service
credentials = flow.step2_exchange(code)
File "C:\utils\python\lib\site-packages\oauth2client_helpers.py", line 133, i
n positional_wrapper
return wrapped(*args, **kwargs)
File "C:\utils\python\lib\site-packages\oauth2client\client.py", line 2089, in
step2_exchange
raise FlowExchangeError(error_msg)
oauth2client.client.FlowExchangeError: invalid_clientUnauthorized

Support UTF-8 filenames/folders

The current script will fail with lots of folders and filenames.

I can get past the UnicodeEncodeError: with this:

reload(sys)
sys.setdefaultencoding('utf-8')

But then it goes on but nothing is shared/changed

python transfer.py "Téáóçãú" [email protected] false
Changing all files at path "Téáóçãú" to owner "[email protected]"
Prefix: [u'T\xe9\xe1\xf3\xe7\xe3\xfa']
Use this link for authorization: link
Verification code: code
User [email protected] is permission ID 05411747774099128436.
Gathering file listings for prefix []...
Folder: Téáóçãú ([], 1CkIpP7rvMP5R1AKaLNEzjRhMGKr2tcPf)
Gathering file listings for prefix [u'T\xe9\xe1\xf3\xe7\xe3\xfa']...
Folder: solto ([], 1aHUnS8GV4TGI_j5CAhuAOHYl4-5kwT8s)

Any chance we can get this? This is still the best method to change permissions with google drive but it chokes with lots of characters :(

Google drive api v3

Is it possible to update the code to work with google drive api v3? (enhancement) since authentification method works quicker for the new ones setting up this script to work?

Error 400: Invalid request

Hey, first off thanks alot for your effort. When I try to run the terminal command it gives me a link for authorization.
However when I press the link I get the following error message from google:

Error 400: invalid_request
The out-of-band (OOB) flow has been blocked in order to keep users secure. Follow the Out-of-Band (OOB) flow Migration Guide linked in the developer docs below to migrate your app to an alternative method.
Request details: redirect_uri=urn:ietf:wg:oauth:2.0:oob

Google's suggested solution seems simple:
image

however I'm not sure how it can be implemnted into your code.

Would really appreciate your help on this.
Thanks.

Error when changing ownership of pdf files

Hi,

On this line in the python code
return service.permissions().update(fileId=drive_item['id'], permissionId=permission_id, body=permission, transferOwnership=True).execute()

I'm getting this error:
An error occurred updating ownership permissions: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files/randomcharacters/permissions/some_numbers?transferOwnership=true&alt=json returned "Insufficient permissions for this file">

Does the code need to be updated to allow for ownership changes to files that have been uploaded to google drive?

Google Shared Folders

How do we use this tool with the newer style "Shortcut to Drive" shared folders?

when google used to "add to my Drive" these shared folders work like any other folder and the tool changes owners perfectly.

but it dosnt seem to see the shortcuts?

Repository contains an example key that end-users should replace

I would suggest using a dummy JSON file for the client_secrets.json instead of an actual client. I just followed the directions to run an example execution of this program, and it seems like it is attempting to use a real key. The key had 2FA, so that is good. However a dummy file should be put in it's place.

Noob Needs Help

I followed your directions to get running and was able to get the client_secrets.json correct. I'm able to verify and link everything. But once I give permission I'm seeing this error:

An error occurred: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files/root/children?alt=json returned "Project XXXXXXXX is not found and cannot be used for API calls. If it is recently created, enable Drive API by visiting https://console.developers.google.com/apis/api/drive.googleapis.com/overview?project=XXXXXXXX then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.">

New syntax

Recommending new syntax:

python transfer.py [--quiet] NEW_OWNER_EMAIL PATH ...

This allows specifying multiple paths.

Also related to another issue (#11).

UnicodeEncodeError: 'ascii' codec can't encode character

I have error:

    Creating new ownership permissions.
Traceback (most recent call last):
  File "transfer.py", line 135, in <module>
    process_all_files(service, grant_ownership, {'permission_id': permission_id, 'show_already_owned': show_already_owned }, minimum_prefix_split)
  File "transfer.py", line 112, in process_all_files
    process_all_files(service, callback, callback_args, minimum_prefix, next_prefix, item['id'])
  File "transfer.py", line 112, in process_all_files
    process_all_files(service, callback, callback_args, minimum_prefix, next_prefix, item['id'])
  File "transfer.py", line 106, in process_all_files
    callback(service, item, current_prefix, **callback_args)
  File "transfer.py", line 81, in grant_ownership
    print('An error occurred inserting ownership permissions: {}'.format(e))
UnicodeEncodeError: 'ascii' codec can't encode character u'\u0412' in position 222: ordinal not in range(128)

After that, check this app Transfer Ownership work great

Script no longer works?

Hello and thanks for this much needed script. It looks like that you are no longer able to change the ownership using the API as Google needs a consent screen for every file ownership change? This is what I get when I run the script:

File: 20190511_124214.jpg (['Google Foto', '2019', '05'], 1nrhNTdpsx6BDddQjyGx2HrxtaLMqRUu1jw)
Item b'Google Foto\\2019\\05\\20190511_124214.jpg' needs ownership granted.
    Upgrading existing permissions to ownership.
An error occurred updating ownership permissions: <HttpError 403 when requesting https://www.googleapis.com/drive/v2/files/1nrhNTdpsx6BDddQjyGx2HrxtaLMqRUu1jw/permissions/13961269970869633944?transferOwnership=true&alt=json returned "Consent is required to transfer ownership of a file to another user.". Details: "[{'message': 'Consent is required to transfer ownership of a file to another user.', 'domain': 'global', 'reason': 'consentRequiredForOwnershipTransfer'}]">

Error 400: redirect_uri_mismatch

I keep getting this error, I think it's because of what I put on redirect_uris. But I'm not really sure what I am supposed to put there. Please help me

Installation

Hi, I'm a newbie and having trouble installing this on a Windows machine. Any assistance would be greatly appreciated.

-Danny

Permission Denied

I'm on my Mac and i'm executing the script in this way:
python transfer.py /Users/luca/Google\ Drive/New_Folder\ Custom/ true

When I run the script I get the error below.

schermata 2016-08-03 alle 20 05 57

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.