def create_service(self, host):
credentials = oauth.get_or_create_credentials(
scope=OAUTH_SCOPES, storage_key=STORAGE_KEY)
http = httplib2.Http(ca_certs=utils.get_cacerts_path())
http = credentials.authorize(http)
# Kintaro's server doesn't seem to be able to refresh expired tokens
# properly (responds with a "Stateless token expired" error). So we
# manage state ourselves and refresh slightly more often than once
# per hour.
now = datetime.datetime.now()
if self._last_run is None \
or now - self._last_run >= datetime.timedelta(minutes=50):
credentials.refresh(http)
self._last_run = now
url = DISCOVERY_URL.replace('{host}', host)
return discovery.build('content', 'v1', http=http,
discoveryServiceUrl=url)
评论列表
文章目录