How to create a oAuth request using java?

后端 未结 2 1960
温柔的废话
温柔的废话 2021-02-03 12:07

I need to make a connection with Viagogo website using oAuth. Referring to their documentation I need to create a request similar to the following one

Using the         


        
2条回答
  •  忘了有多久
    2021-02-03 12:23

    I'm assuming you're trying to get the access token (e.g you're calling SimpleOAuthAccessRequest). Scribe's OauthService has methods to handle this.

    BUT ... if you're going to do it manually, here is what's wrong with your code - at least with what you've listed here. I'm assuming you've configured scribe correctly.

    • don't pass the consumer secret with your request, that is only for signing the request
    • you should use addOauthParameter vs addQueryStringParameter
    • you should use the Scribe constants
    • you need to sign the request (again, Scribe's OauthService has help method for signing request)

    Here's your updated snippet of code.

    UPDATE: Have Scribe provide all the Oauth parameters for you

    OAuthRequest request = new OAuthRequest(Verb.GET, ...
    //since you're just passing Oauth parameters and nothing else, 
    //you can use signRequest will create Oauth Parameters for you
    service.signRequest(OAuthConstants.EMPTY_TOKEN, request)
    Response response = request.send()
    

提交回复
热议问题