12
12
from apiclient .errors import HttpError
13
13
from oauth2client .file import Storage
14
14
from oauth2client .client import flow_from_clientsecrets
15
- from oauth2client .tools import run
16
- from optparse import OptionParser
15
+ from oauth2client .tools import argparser , run_flow
17
16
18
17
19
18
# CLIENT_SECRETS_FILE, name of a file containing the OAuth 2.0 information for
20
19
# this application, including client_id and client_secret. You can acquire an
21
- # ID/secret pair from the API Access tab on the Google APIs Console
22
- # http ://code. google.com/apis/console#access
20
+ # ID/secret pair from the API Access tab on the Google Developers Console
21
+ # https ://console.developers. google.com/project/_/apiui/credential
23
22
# For more information about using OAuth2 to access Google APIs, please visit:
24
23
# https://developers.google.com/accounts/docs/OAuth2
25
24
# For more information about the client_secrets.json file format, please visit:
39
38
To make this sample run you will need to populate the client_secrets.json file
40
39
found at:
41
40
%s
42
- with information from the APIs Console
43
- https://developers.google.com/console
41
+ with information from the Developers Console
42
+ https://console. developers.google.com
44
43
45
44
For more information about the client_secrets.json file format, please visit:
46
45
https://developers.google.com/api-client-library/python/guide/aaa_client_secrets
47
46
""" % os .path .abspath (os .path .join (os .path .dirname (__file__ ),
48
47
CLIENT_SECRETS_FILE ))
49
48
50
49
# Authorize the request and store authorization credentials.
51
- def get_authenticated_service ():
50
+ def get_authenticated_service (args ):
52
51
flow = flow_from_clientsecrets (CLIENT_SECRETS_FILE ,
53
52
scope = YOUTUBE_READ_WRITE_SCOPE ,
54
53
message = MISSING_CLIENT_SECRETS_MESSAGE )
@@ -57,7 +56,7 @@ def get_authenticated_service():
57
56
credentials = storage .get ()
58
57
59
58
if credentials is None or credentials .invalid :
60
- credentials = run (flow , storage )
59
+ credentials = run_flow (flow , storage , args )
61
60
62
61
return build (YOUTUBE_API_SERVICE_NAME , YOUTUBE_API_VERSION ,
63
62
http = credentials .authorize (httplib2 .Http ()))
@@ -73,16 +72,15 @@ def unset_watermark(youtube, channel_id):
73
72
74
73
75
74
if __name__ == "__main__" :
76
- parser = OptionParser ()
77
- parser .add_option ("--channelid" , dest = "channelid" ,
75
+ argparser .add_argument ("--channelid" , dest = "channelid" ,
78
76
help = "Required; id of channel whose watermark you're updating." )
79
- ( options , args ) = parser .parse_args ()
80
-
81
- if not options .channelid :
82
- parser .print_help ()
77
+ args = argparser .parse_args ()
78
+
79
+ if not args .channelid :
80
+ argparser .print_help ()
83
81
exit ()
84
82
85
- youtube = get_authenticated_service ()
83
+ youtube = get_authenticated_service (args )
86
84
87
- unset_watermark (youtube , options .channelid )
85
+ unset_watermark (youtube , args .channelid )
88
86
print "The watermark was successfully unset."
0 commit comments