@@ -160,33 +160,30 @@ def get_credentials(self):
160
160
return self .get_service_account_credentials ()
161
161
else :
162
162
# Try to retrieve Application Default Credentials
163
- project_id = self .project_id
164
- credentials = self .get_application_default_credentials (project_id )
163
+ credentials = self .get_application_default_credentials ()
165
164
if not credentials :
166
165
credentials = self .get_user_account_credentials ()
167
166
return credentials
168
167
169
- @staticmethod
170
- def get_application_default_credentials (project_id ): # pragma: no cover
168
+ def get_application_default_credentials (self ):
171
169
"""
172
- Given a project_id tries to retrieve the
173
- "default application credentials"
170
+ This method tries to retrieve the "default application credentials"
174
171
Could be useful for running code on Google Cloud Platform
175
172
"""
176
- credentials = None
173
+ from oauth2client .client import AccessTokenRefreshError
174
+ try :
175
+ from googleapiclient .discovery import build
176
+ from googleapiclient .errors import HttpError
177
+ except :
178
+ from apiclient .discovery import build
179
+ from apiclient .errors import HttpError
177
180
try :
178
181
from oauth2client .client import GoogleCredentials
179
- from oauth2client .client import AccessTokenRefreshError
180
182
from oauth2client .client import ApplicationDefaultCredentialsError
181
- try :
182
- from googleapiclient .discovery import build
183
- from googleapiclient .errors import HttpError
184
- except :
185
- from apiclient .discovery import build
186
- from apiclient .errors import HttpError
187
183
except ImportError :
188
184
return None
189
185
186
+ credentials = None
190
187
try :
191
188
credentials = GoogleCredentials .get_application_default ()
192
189
except ApplicationDefaultCredentialsError :
@@ -196,7 +193,7 @@ def get_application_default_credentials(project_id): # pragma: no cover
196
193
jobs = bigquery_service .jobs ()
197
194
job_data = {'configuration' : {'query' : {'query' : 'SELECT 1' }}}
198
195
try :
199
- jobs .insert (projectId = project_id , body = job_data ).execute ()
196
+ jobs .insert (projectId = self . project_id , body = job_data ).execute ()
200
197
except (AccessTokenRefreshError , HttpError , TypeError ):
201
198
return None
202
199
return credentials
@@ -616,12 +613,14 @@ def read_gbq(query, project_id=None, index_col=None, col_order=None,
616
613
https://developers.google.com/api-client-library/python/apis/bigquery/v2
617
614
618
615
Authentication to the Google BigQuery service is via OAuth 2.0.
619
- By default "application default credentials" are used.
620
- If default application credentials are not found or are restrictive -
621
- User account credentials are used. You will be asked to
622
- grant permissions for product name 'pandas GBQ'. It is also posible
623
- to authenticate via service account credentials by using
624
- private_key parameter.
616
+ If "private_key" is not provided:
617
+ By default "application default credentials" are used [new behavior]
618
+ If default application credentials are not found or are restrictive -
619
+ User account credentials are used. In this case - you will be asked to
620
+ grant permissions for product name 'pandas GBQ'.
621
+ If "private_key" is provided:
622
+ It is also posible to authenticate via service account credentials
623
+ by using this parameter.
625
624
626
625
Parameters
627
626
----------
@@ -713,13 +712,14 @@ def to_gbq(dataframe, destination_table, project_id, chunksize=10000,
713
712
Documentation is available at
714
713
https://developers.google.com/api-client-library/python/apis/bigquery/v2
715
714
716
- Authentication to the Google BigQuery service is via OAuth 2.0.
717
- By default "application default credentials" are used.
718
- If default application credentials are not found or are restrictive -
719
- User account credentials are used. You will be asked to
720
- grant permissions for product name 'pandas GBQ'. It is also posible
721
- to authenticate via service account credentials by using
722
- private_key parameter.
715
+ If "private_key" is not provided:
716
+ By default "application default credentials" are used [new behavior]
717
+ If default application credentials are not found or are restrictive -
718
+ User account credentials are used. In this case - you will be asked to
719
+ grant permissions for product name 'pandas GBQ'.
720
+ If "private_key" is provided:
721
+ It is also posible to authenticate via service account credentials
722
+ by using this parameter.
723
723
724
724
Parameters
725
725
----------
0 commit comments