Skip to content

Instantly share code, notes, and snippets.

@otofune
Created June 23, 2020 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otofune/4d7495d1455dde60907ac52dc7f98a63 to your computer and use it in GitHub Desktop.
Save otofune/4d7495d1455dde60907ac52dc7f98a63 to your computer and use it in GitHub Desktop.
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