我成功获得了访问令牌,但在使用OAUTH 2.0凭据创建客户端后遇到了问题。我几乎遵循github上的python SDK示例中的示例。
这是我的代码:
from utils import import_oauth2_credentials
from uber_rides.client import UberRidesClient
from uber_rides.session import OAuth2Credential
from uber_rides.session import Session
credentials2 = import_oauth2_credentials()
oauth2credential = OAuth2Credential(
client_id=credentials2.get('client_id'),
access_token=credentials2.get('access_token'),
expires_in_seconds=credentials2.get('expires_in_seconds'),
scopes=credentials2.get('scopes'),
grant_type=credentials2.get('grant_type'),
redirect_url=credentials2.get('redirect_url'),
client_secret=credentials2.get('client_secret'),
refresh_token=credentials2.get('refresh_token'),
)
session = Session(oauth2credential=oauth2credential)
uber_client = UberRidesClient(session, sandbox_mode=True)
print uber_client
response = uber_client.get_products(37.77, -122.41)
print response
我可以打印出uber_client对象:
<uber_rides.client.UberRidesClient object at 0x10deeae50>
我收到的错误信息是:
raise ClientError(response)
ClientError: The request contains bad syntax or cannot be filled due to a fault from the client sending the request."
我想知道是什么问题。谢谢你的帮助!
答案 0 :(得分:0)
我解决了这些问题。问题是我从oauth2_session_store.yaml文件中导入了oauth凭据,该文件未正确更新以反映我当前的access_token。
根本问题:
credentials2 = import_oauth2_credentials()
所以吸取教训:检查访问令牌以查看它是否是最新的。