Я хотел бы создать пользовательскую карту Google с помощью API Google Maps Engine. Для этого мне нужно отправить некоторые данные в API Google Maps Engine. Я пытаюсь использовать клиентскую библиотеку API Google для Python, чтобы создать объект потока OAuth 2.0
, чтобы получить необходимое разрешение, чтобы разрешить отправлять мои данные в API Карт Google, но я получаю сообщение AccessTokenRefreshError: invalid_grant
, когда я пытаюсь выполнить мой запрос.AccessTokenRefreshError: invalid_grant при попытке отправить данные в API Google Maps Engine с помощью клиентской библиотеки API Google для Python
Вот мой код:
import httplib2
import sys
from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
with open('C:\\Users\\User\\Documents\\client_id.txt') as f:
client_id = f.read()
with open('C:\\Users\\User\\Documents\\client_secret.txt') as f:
client_secret = f.read()
with open('C:\\Users\\User\\Documents\\api_key.txt') as f:
api_key = f.read()
scope = 'https://www.googleapis.com/auth/mapsengine'
flow = OAuth2WebServerFlow(client_id, client_secret, scope)
storage = Storage('C:\\Users\\User\\Documents\\credentials.dat')
credentials = storage.get()
credentials = run(flow, storage) #Opens my browser asking me to sign in with a Google account
http = httplib2.Http()
http = credentials.authorize(http)
service = build('mapsengine', 'v1', developerKey=api_key, http=http)
table = service.tables()
request = table.files().insert(id='11', filename='C:\\Users\\User\\Documents\\GitHub\\Turf_project\\df_json', media_body=None)
response = request.execute()
---------------------------------------------------------------------------
AccessTokenRefreshError Traceback (most recent call last)
<ipython-input-18-698f94a34d91> in <module>()
----> 1 response = request.execute()
C:\Users\User\AppData\Local\Enthought\Canopy32\User\lib\site-packages\oauth2client\util.pyc in positional_wrapper(*args, **kwargs)
130 else: # IGNORE
131 pass
--> 132 return wrapped(*args, **kwargs)
133 return positional_wrapper
134
C:\Users\User\AppData\Local\Enthought\Canopy32\User\lib\site-packages\apiclient\http.pyc in execute(self, http, num_retries)
714
715 resp, content = http.request(str(self.uri), method=str(self.method),
--> 716 body=self.body, headers=self.headers)
717 if resp.status < 500:
718 break
C:\Users\User\AppData\Local\Enthought\Canopy32\User\lib\site-packages\oauth2client\util.pyc in positional_wrapper(*args, **kwargs)
130 else: # IGNORE
131 pass
--> 132 return wrapped(*args, **kwargs)
133 return positional_wrapper
134
C:\Users\User\AppData\Local\Enthought\Canopy32\User\lib\site-packages\oauth2client\client.pyc in new_request(uri, method, body, headers, redirections, connection_type)
492 if resp.status in REFRESH_STATUS_CODES:
493 logger.info('Refreshing due to a %s' % str(resp.status))
--> 494 self._refresh(request_orig)
495 self.apply(headers)
496 return request_orig(uri, method, body, clean_headers(headers),
C:\Users\User\AppData\Local\Enthought\Canopy32\User\lib\site-packages\oauth2client\client.pyc in _refresh(self, http_request)
661 self._updateFromCredential(new_cred)
662 else:
--> 663 self._do_refresh_request(http_request)
664 finally:
665 self.store.release_lock()
C:\Users\User\AppData\Local\Enthought\Canopy32\User\lib\site-packages\oauth2client\client.pyc in _do_refresh_request(self, http_request)
708 except StandardError:
709 pass
--> 710 raise AccessTokenRefreshError(error_msg)
711
712 def _revoke(self, http_request):
AccessTokenRefreshError: invalid_grant
Может кто-нибудь объяснить, почему я получаю эту ошибку, даже если я войти в систему с моим аккаунтом Google?