12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- from google_auth_oauthlib.flow import Flow
- from colorama import init, Fore
- import codecs
- SCOPES = ['https://www.googleapis.com/auth/youtube.upload']
- API_SERVICE_NAME = 'youtube'
- API_VERSION = 'v3'
- VALID_PRIVACY_STATUSES = ('public', 'private', 'unlisted')
- def get_credentials(secrets):
- flow = Flow.from_client_secrets_file(
- 'c:\\keys\\.client_secrets.json',
- scopes= ['https://www.googleapis.com/auth/youtube.upload'],
- redirect_uri='https://m.hhh.com.tw/hhh-home-mb/index.html')
-
- auth_url, _ = flow.authorization_url(prompt='consent')
- init(autoreset=True)
- print()
- print(Fore.GREEN + 'Please go to this URL: ' + Fore.CYAN + str(auth_url))
-
-
- print()
- code = input(Fore.GREEN + 'Enter the authorization code: ')
- flow.fetch_token(code=code)
- print()
- return flow.credentials
-
-
-
- tok=get_credentials('c:\\keys\\.client_secrets.json')
- print(tok)
- print(tok.refresh_token)
- print(tok.to_json())
- fw=codecs.open('c:\\keys\\storage.json','w','utf-8')
- fw.write(tok.to_json())
- fw.close()
|