无法使用 OAUTH 2.0 客户端使用优步 API 请求优步乘车(或其他 class 方法)

Can't request uber rides (or other class methods) with OAUTH 2.0 client using Uber API

我成功获得了访问令牌,但是 运行 在使用 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."

我想知道是什么问题。感谢您的帮助!

我解决了问题。问题是我从 oauth2_session_store.yaml 文件导入了 oauth 凭据,该文件未正确更新以反映我当前的 access_token.

根本问题:

credentials2 = import_oauth2_credentials()

吸取教训:检查访问令牌是否是最新的。