diff --git a/v2/python/adsense_util.py b/v2/python/adsense_util.py index eed3165..db86af8 100644 --- a/v2/python/adsense_util.py +++ b/v2/python/adsense_util.py @@ -12,7 +12,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - """Utility class to handle account and credential management.""" from google_auth_oauthlib.flow import InstalledAppFlow @@ -37,6 +36,7 @@ # This access scope grants read-only access to the authenticated user's account. SCOPES = ['https://www.googleapis.com/auth/adsense.readonly'] + def get_account_id(service): """Gets the AdSense account id, letting the user choose if multiple exist. @@ -54,11 +54,11 @@ def get_account_id(service): print('Multiple accounts were found. Please choose:') for i, account in enumerate(response['accounts']): print(' %d) %s (%s)' % (i + 1, account['displayName'], account['name'])) - selection = (input('Please choose number 1-%d>' - % (len(response['accounts'])))) + selection = (input('Please choose number 1-%d>' % (len(response['accounts'])))) account_id = response['accounts'][int(selection) - 1]['name'] return account_id + def get_adsense_credentials(overwrite_existing_credentials=False): """Gets AdSense credentials (locally cached or by running the OAuth flow). @@ -70,12 +70,11 @@ def get_adsense_credentials(overwrite_existing_credentials=False): A credential object required for making authenticated API requests. """ credentials = None - if (os.path.isfile(CREDENTIALS_FILE) and not overwrite_existing_credentials - and not ALWAYS_REQUIRE_AUTHENTICATION ): + if (os.path.isfile(CREDENTIALS_FILE) and not overwrite_existing_credentials and not ALWAYS_REQUIRE_AUTHENTICATION): credentials = Credentials.from_authorized_user_file(CREDENTIALS_FILE) else: flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES) - credentials = flow.run_console() + credentials = flow.run_local_server() with open(CREDENTIALS_FILE, 'w') as credentials_file: credentials_json = credentials.to_json() if isinstance(credentials_json, str):