Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current account name in google colab

Tags:

For example, if my current Colab instance is signed in as

[email protected]

Is it possible to get the name "myColab" in ipython?

What is the command to do this?

I want to do this because I may run two Colab, and they generate files, I want to tag these files with Colab account name, so I know which account generate these files.

like image 462
user15964 Avatar asked Oct 15 '18 13:10

user15964


1 Answers

By default, the backends are not authenticated for any particular user. But, if you've gone through through the gcloud auth flow, you can retrieve the email address like so:

https://colab.research.google.com/drive/1VVWs_pcjjz2vg0H2Ti6-12FzcCojRF6a

The key snippet is:

import requests
gcloud_token = !gcloud auth print-access-token
gcloud_tokeninfo = requests.get('https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=' + gcloud_token[0]).json()
print(gcloud_tokeninfo['email'])
like image 132
Bob Smith Avatar answered Oct 26 '22 23:10

Bob Smith