OAuth Handshake Copy Error

送分小仙女□ 提交于 2019-12-12 06:06:03

问题


I am trying to build a PoC with the API REST of Copy but I have a problem when I try to get the ACCESS TOKEN:

Message: oauth_problem=signature_invalid&debug_sbs=GET&https%3A%2F%2Fapi.copy.com%...

@app.route('/get_access_token')
def get_access_token():
    print "Get Access Token"
    oauth_verifier = request.args['oauth_verifier']
    oauth_token = request.args['oauth_token']
    print oauth_token + " & " + oauth_verifier

    # Create your consumer with the proper key/secret.
    consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
    print "Consumer: ", consumer
    client = oauth.Client(consumer)
    url = access_url + "?oauth_verifier=%s&oauth_token=%s" % (oauth_verifier, oauth_token)
    print url
    resp, content = client.request(url, "GET")
    print "Resp: ", resp
    print "Content: ", content

    return content

I would appreciate any help.


回答1:


I have been able to solve my own issue. The problem was the creation of a new consumer (I had one for the first step of the oauth handshake) and not using the oauth.Token provided by the library (I put the oauth_verifier and the oauth_token with a workaround)

The solution:

@app.route('/get_access_token')
def get_access_token():
    print "Get Access Token"
    try:
        oauth_verifier = request.args['oauth_verifier']
        oauth_token = request.args['oauth_token']
        print oauth_token + " & " + oauth_verifier

        token = oauth.Token(oauth_token, request_token_secret) # request_token_secret is global
        token.set_verifier(oauth_verifier)
        client = oauth.Client(consumer, token) #consumer is global

        url = "https://api.copy.com/oauth/access"
        resp, content = client.request(url, "GET")
        print "Resp: ", resp
        print "Content: ", content
        return content

    except Exception as e:
        return e.message()


来源:https://stackoverflow.com/questions/28387644/oauth-handshake-copy-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!