Patreon / patreon-java

Interact with the Patreon API via OAuth
Apache License 2.0
52 stars 26 forks source link

Is this usecase supported? #1

Closed jantje closed 6 years ago

jantje commented 7 years ago

Hi I would love to implement following use case 1)Users starts java program (eclipse to be precise) 2)Based on information stored in eclipse the java program checks whether the user is a patron off me (with the correct rewards) 3)If so I can disable/enable features. I can easily handle step 1 and 3 but I seem to be unable to get my head around step 2. There is only one constructor for oAuth which takes a client ID and client secret. When I take my client ID and my client secret I get back a oAuth but when I call JSONObject tokens = oauthClient.getTokens(my_refresh_token, ""); I always get a null back

I tried adding a getTokens variant

    public JSONObject getTokens(String code) {
    final Map<String, String> params = new HashMap<>();
    params.put("grant_type", "authorization_code");
    params.put("code", code);
    params.put("client_id", this._clientID);
    params.put("client_secret", this._clientSecret);
    return this.updateToken(params)

but I still get null

jantje commented 7 years ago

I noticed that my creators refresh token is not updated so it looks as if I do not get to the server.

jantje commented 7 years ago

I see following info in the log Server returned HTTP response code: 401 for URL: https://api.patreon.com/oauth2/token

jantje commented 7 years ago

It is this line that throws the exception. final BufferedReader stream = new BufferedReader(new InputStreamReader(connection.getInputStream())); It does so with the original getTokens and with my variant.

adamint commented 6 years ago

This use case is supported. Query your patrons & compare ids

21echoes commented 6 years ago

hey @jantje ! sorry this slipped through the cracks. It sounds like you're not properly keeping your refresh token up to date, so you're getting an HTTP 401. Please make sure to handle 401s by calling refreshToken(myRefreshToken). I'm going to close the issue for now, but please do open a new one if you cannot get this working