@@ -171,25 +171,28 @@ def get_application_default_credentials(self):
171
171
This method tries to retrieve the "default application credentials"
172
172
Could be useful for running code on Google Cloud Platform
173
173
"""
174
- from oauth2client .client import AccessTokenRefreshError
175
- try :
176
- from googleapiclient .discovery import build
177
- from googleapiclient .errors import HttpError
178
- except :
179
- from apiclient .discovery import build
180
- from apiclient .errors import HttpError
174
+ oauth2client_library_imported = False
181
175
try :
182
176
from oauth2client .client import GoogleCredentials
177
+ from oauth2client .client import AccessTokenRefreshError
183
178
from oauth2client .client import HttpAccessTokenRefreshError
184
179
from oauth2client .client import ApplicationDefaultCredentialsError
180
+ oauth2client_library_imported = True
181
+ from googleapiclient .discovery import build
182
+ from googleapiclient .errors import HttpError
185
183
except ImportError :
184
+ from apiclient .discovery import build
185
+ from apiclient .errors import HttpError
186
+
187
+ if not oauth2client_library_imported :
186
188
return None
187
189
188
190
credentials = None
189
191
try :
190
192
credentials = GoogleCredentials .get_application_default ()
191
193
except ApplicationDefaultCredentialsError :
192
194
return None
195
+
193
196
# Check if the application has rights to the BigQuery project
194
197
bigquery_service = build ('bigquery' , 'v2' , credentials = credentials )
195
198
jobs = bigquery_service .jobs ()
@@ -617,14 +620,16 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
617
620
https://developers.google.com/api-client-library/python/apis/bigquery/v2
618
621
619
622
Authentication to the Google BigQuery service is via OAuth 2.0.
620
- If "private_key" is not provided:
621
- By default "application default credentials" are used [new behavior]
622
- If default application credentials are not found or are restrictive -
623
- User account credentials are used. In this case - you will be asked to
623
+ - If "private_key" is not provided:
624
+ By default "application default credentials" are used.
625
+
626
+ .. versionadded:: 0.19.0
627
+
628
+ If default application credentials are not found or are restrictive,
629
+ user account credentials are used. In this case, you will be asked to
624
630
grant permissions for product name 'pandas GBQ'.
625
- If "private_key" is provided:
626
- It is also posible to authenticate via service account credentials
627
- by using this parameter.
631
+ - If "private_key" is provided:
632
+ Service account credentials will be used to authenticate.
628
633
629
634
Parameters
630
635
----------
@@ -731,14 +736,17 @@ def to_gbq(dataframe, destination_table, project_id, chunksize=10000,
731
736
Documentation is available at
732
737
https://developers.google.com/api-client-library/python/apis/bigquery/v2
733
738
734
- If "private_key" is not provided:
735
- By default "application default credentials" are used [new behavior]
736
- If default application credentials are not found or are restrictive -
737
- User account credentials are used. In this case - you will be asked to
739
+ Authentication to the Google BigQuery service is via OAuth 2.0.
740
+ - If "private_key" is not provided:
741
+ By default "application default credentials" are used.
742
+
743
+ .. versionadded:: 0.19.0
744
+
745
+ If default application credentials are not found or are restrictive,
746
+ user account credentials are used. In this case, you will be asked to
738
747
grant permissions for product name 'pandas GBQ'.
739
- If "private_key" is provided:
740
- It is also posible to authenticate via service account credentials
741
- by using this parameter.
748
+ - If "private_key" is provided:
749
+ Service account credentials will be used to authenticate.
742
750
743
751
Parameters
744
752
----------
0 commit comments