You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am following the tutorial provided for the Youtube Data API
The following code :
# Sample Python code for user authorizationimportosfromoauth2client.fileimportStoragefromgoogleapiclient.discoveryimportbuildfromgoogle_auth_oauthlib.flowimportInstalledAppFlowCLIENT_SECRETS_FILE="client_secret.json"SCOPES= ['https://www.googleapis.com/auth/youtube']
API_SERVICE_NAME='youtube'API_VERSION='v3'CREDENTIALS='credentials.json'defget_authenticated_service():
flow=InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)
storage=Storage(CREDENTIALS)
credentials=storage.get()
ifnotcredentialsorcredentials.invalid:
credentials=flow.run_local_server(host='localhost',
port=8080,
authorization_prompt_message='Please visit this URL: {url}',
success_message='The auth flow is complete; you may close this window.',
open_browser=True)
storage.put(credentials)
returnbuild(API_SERVICE_NAME, API_VERSION, credentials=credentials)
defchannels_list_by_username(service, **kwargs):
results=service.channels().list(**kwargs).execute()
print('This channel\'s ID is %s. Its title is %s, and it has %s views.'%
(results['items'][0]['id'],
results['items'][0]['snippet']['title'],
results['items'][0]['statistics']['viewCount']))
if__name__=='__main__':
os.environ['OUATHLIB_INSECURE_TRANSPORT'] ='1'service=get_authenticated_service()
channels_list_by_username(service, part='snippet,contentDetails,statistics',
forUsername='GoogleDevelopers')
The storage of credentials is taken from this Guide
I think the Credential object provided by this library does not provided to_json() method, unlike the old library oauth2client.client.Credential, hence creating the error.
None of the guides or examples provided by this library or the above mentioned tutorial provides a way around this problem. It would be nice if you could provide a way to store the Credential object returned by this library or suggest an alternative way using this library to store.
P.S. : As the old library oauth2client is not supported, and this library is recommended. It would be nice if you could provide a way to store the Credential object returned from this library.
The text was updated successfully, but these errors were encountered:
If you don't mind me asking, where should one raise a request to update the samples and related docs?
I have been searching for an solution for a few days, and all the examples always went back to oauth2client Storage. It would be really useful for newbies like me, if this was either documented properly, or proper samples were at least provided.
I am following the tutorial provided for the Youtube Data API
The following code :
Produces the following error :
The storage of credentials is taken from this Guide
I think the
Credential
object provided by this library does not providedto_json()
method, unlike the old libraryoauth2client.client.Credential
, hence creating the error.None of the guides or examples provided by this library or the above mentioned tutorial provides a way around this problem. It would be nice if you could provide a way to store the
Credential
object returned by this library or suggest an alternative way using this library to store.P.S. : As the old library
oauth2client
is not supported, and this library is recommended. It would be nice if you could provide a way to store theCredential
object returned from this library.The text was updated successfully, but these errors were encountered: