-
-
Save otofune/4d7495d1455dde60907ac52dc7f98a63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pathlib | |
import google.oauth2.credentials | |
def construct_credentials_by_gdfs_configuration(): | |
gdfs_path = pathlib.Path(os.environ['HOME']).joinpath('./.config/Google/DriveFS') | |
gdfs_account_id = None | |
with open(gdfs_path.joinpath('./signin'), 'r') as f: | |
gdfs_account_id = f.read() | |
gdfs_token = None | |
with open(gdfs_path.joinpath(f'./{gdfs_account_id}/refresh_token'), 'rb') as f: | |
# 3 byte ゴミがついてるので捨てる | |
f.read(3) | |
gdfs_token = json.loads(f.read().decode('utf-8')) | |
return google.oauth2.credentials.Credentials( | |
token=gdfs_token['access_token'], | |
refresh_token=gdfs_token['refresh_token'], | |
scopes=gdfs_token['scope'].split(' '), | |
# refresh は無効にする | |
client_id=None, | |
client_secret=None, | |
token_uri='https://accounts.google.com/o/oauth2/token' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment