【问题标题】:Can't request uber rides (or other class methods) with OAUTH 2.0 client using Uber API无法使用 Uber API 通过 OAUTH 2.0 客户端请求 uber 乘车(或其他类方法)
【发布时间】:2016-02-10 19:35:27
【问题描述】:

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

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

【问题讨论】:

    标签: python oauth-2.0 uber-api


    【解决方案1】:

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

    根本问题:

    credentials2 = import_oauth2_credentials()
    

    因此吸取了教训:检查访问令牌以查看它是否是最新的。

    【讨论】:

      猜你喜欢
      • 2020-11-17
      • 2015-07-09
      • 2016-05-21
      • 2016-11-08
      • 2016-08-07
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多