调用street_view_publish_service_client
的api时出现以下错误。看来我的令牌已过期......
GaxError(RPC失败,由终止的RPC的< _Rendezvous引起 with(StatusCode.UNAUTHENTICATED,请求具有无效的身份验证 证书。预期的OAuth 2访问令牌,登录cookie或其他 有效的身份验证凭据。看到 https://developers.google.com/identity/sign-in/web/devconsole-project)>)
在调用StreetViewPublishServiceClient的API之前,是否会自动刷新凭据的访问令牌?如果没有,我该如何刷新访问令牌? 以下是示例代码。
pip install gapic-google-maps-streetview_publish-v1
pip install google-auth
from google.streetview.publish.v1 import street_view_publish_service_client
import google.oauth2.credentials
def run():
creds = google.oauth2.credentials.Credentials(
MY_ACCESS_TOKEN,
refresh_token=MY_REFRESH_TOKEN,
token_uri="https://www.googleapis.com/oauth2/v4/token",
client_id=GOOGLE_CLINET_ID,
client_secret=GOOGLE_CLIENT_SECRET)
client = street_view_publish_service_client.StreetViewPublishServiceClient(
credentials=creds)
upload_ref = client.start_upload()
print upload_ref
答案 0 :(得分:0)
这次修改怎么样?
from google.streetview.publish.v1 import street_view_publish_service_client
import google.oauth2.credentials
import google.auth.transport.requests # Added
def run():
creds = google.oauth2.credentials.Credentials(
MY_ACCESS_TOKEN,
refresh_token=MY_REFRESH_TOKEN,
token_uri="https://www.googleapis.com/oauth2/v4/token",
client_id=GOOGLE_CLINET_ID,
client_secret=GOOGLE_CLIENT_SECRET)
creds.refresh(google.auth.transport.requests.Request()) # Added
client = street_view_publish_service_client.StreetViewPublishServiceClient(
credentials=creds)
upload_ref = client.start_upload()
print upload_ref
如果这对你没用,我很抱歉。