首页 > 解决方案 > 授权请求中的Upwork api Oauth2.0 redirect_url错误

问题描述

  1. 我收到凭据并从https://github.com/upwork/python-upwork-oauth2/tree/master/example运行 myapp.py
  2. 我的代码看起来像
def get_desktop_client():
    config = upwork.Config(
        {
            "client_id": "MYCLIENTID",
            "client_secret": "CLIENTSECRET",
            "redirect_uri": "https://a.callback.url",
        }
    )
    
    # If token data already known and saved, you can reuse them
    # by adding 'token' parameter to the config
    # token = {'access_token': 'xxxxxxxxxxxxxxxxxx', 'expires_at': 1590479276.547947, 'expires_in': '86400', 'refresh_token': 'xxxxxxxxxxxxxxxxxxxxxxxx', 'token_type': 'Bearer'}
    # config = upwork.Config({'client_id': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'client_secret': 'xxxxxxxxxxxxx', 'token': token})

    client = upwork.Client(config)

    try:
        config.token
    except AttributeError:
        authorization_url, state = client.get_authorization_url()
        # cover "state" flow if needed
        authz_code = input(
            "Please enter the full callback URL you get "
            "following this link:\n{0}\n\n> ".format(authorization_url)
        )
        print("Retrieving access and refresh tokens.... ")
        token = client.get_access_token(authz_code)
        # WARNING: the access token will be refreshed automatically for you
        # in case it's expired, i.e. expires_at < time(). Make sure you replace the
        # old token accordingly in your security storage. Call client.get_actual_config
        # periodically to sync-up the data
        pprint(token)
        print("OK")

    # For further use you can store ``token`` data somewhere

    return client


if __name__ == "__main__":
   
    client = get_desktop_client()

    try:
        print("My info")
        pprint(auth.Api(client).get_user_info())
        # pprint(search.Api(client).find({'q': 'php'}))
        # pprint(team.Api(client).add_activity('mytestcompany', 'mytestcompany', {'code': 'team-task-001', 'description': 'Description', 'all_in_company': '1'}))
        # pprint(time.Gds(client).get_by_freelancer_full('mnovozhilov', {'tq': quote('SELECT task, memo WHERE worked_on >= "2017-06-01" AND worked_on <= "2017-06-02"')}))
    except Exception as e:
        # print("Exception at %s %s" % (client.last_method, client.last_url))
        raise e
  1. 单击此链接后,我被重定向到登录 upwork 帐户
  2. 登录后,我看到这个错误

为什么我错了?请告诉我如何解决它。我会很感激

标签: pythonoauth-2.0

解决方案


推荐阅读