2020
2121from apiclient .discovery import build
2222import httplib2
23- from oauth2client import client
23+ from oauth2client . service_account import ServiceAccountCredentials
2424
2525
2626SERVICE_ACCOUNT_EMAIL = (
3333
3434
3535def main ():
36- # Load the key in PKCS 12 format that you downloaded from the Google APIs
37- # Console when you created your Service account.
38- f = file ('key.p12' , 'rb' )
39- key = f .read ()
40- f .close ()
41-
4236 # Create an httplib2.Http object to handle our HTTP requests and authorize it
4337 # with the Credentials. Note that the first parameter, service_account_name,
4438 # is the Email address created for the Service account. It must be the email
4539 # address associated with the key that was created.
46- credentials = client .SignedJwtAssertionCredentials (
40+ # The second parameter is the path to your PKCS 12 key
41+ credentials = ServiceAccountCredentials .from_p12_keyfile (
4742 SERVICE_ACCOUNT_EMAIL ,
48- key ,
49- scope = 'https://www.googleapis.com/auth/androidpublisher' )
43+ ' key.p12' ,
44+ scopes = 'https://www.googleapis.com/auth/androidpublisher' )
5045 http = httplib2 .Http ()
5146 http = credentials .authorize (http )
5247
@@ -70,7 +65,7 @@ def main():
7065 print 'versionCode: %s, binary.sha1: %s' % (
7166 apk ['versionCode' ], apk ['binary' ]['sha1' ])
7267
73- except client .AccessTokenRefreshError :
68+ except oauth2client . client .AccessTokenRefreshError :
7469 print ('The credentials have been revoked or expired, please re-run the '
7570 'application to re-authorize' )
7671
0 commit comments