Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No documentation on how to refresh a creator access token #16

Open
Vaerys-Dawn opened this issue Mar 14, 2018 · 4 comments
Open

No documentation on how to refresh a creator access token #16

Vaerys-Dawn opened this issue Mar 14, 2018 · 4 comments

Comments

@Vaerys-Dawn
Copy link

Vaerys-Dawn commented Mar 14, 2018

To refresh your creator's access token you need to be connected via OAUth there was no example explaining how to do so. I recommend adding an example to the readme.md to explain how to do so.

This is the code i had to use in order to refresh the token

//Id, token, and secret loaded from patreon.txt file.
public static void refreshPatreonToken(String clientID, String clientSecret, String refreshToken) {
    try {
        PatreonOAuthpatreonOAuth = new PatreonOAuth(clientID, clientSecret, "");
        PatreonOAuth.TokensResponse refresh = patreonOAuth.refreshTokens(refreshToken);
        StringBuffer tokenData = new StringBuffer();
        tokenData.append(refresh.getAccessToken() + "\n");
        tokenData.append(clientID + "\n");
        tokenData.append(clientSecret + "\n");
        tokenData.append(refresh.getRefreshToken());
        FileHandler.writeToFile(Constants.FILE_PATREON_TOKEN, tokenData.toString(), true);
        patreonApi = new PatreonAPI(refresh.getAccessToken());
    } catch (HttpStatusException e) {
          if (e.getStatusCode() == 401) {
              System.out.println("Refresh Token Invalid.);
              return;
         }
         e.printStackTrace();
    } catch (IOException e) {
         e.printStackTrace();
    }
}```
@jrsun
Copy link
Contributor

jrsun commented Mar 19, 2018

Hi! First of all, thanks for writing this code and letting us know about this gap in our documentation. We're in the middle of improvements to our client libs, and I'll be sure to forward this to the relevant parties so that they know about it.

@decmurphy
Copy link

@Vaerys-Dawn - did this code actually work for you? When I wanted to refresh my tokens, I had to change the following line in com.patreon.PatreonOAuth from

private static final String GRANT_TYPE_TOKEN_REFRESH = "token_refresh";
to
private static final String GRANT_TYPE_TOKEN_REFRESH = "refresh_token";

as per the official Patreon docs. I'm about to submit a pull request with the change, but your comment above has made me second-guess myself.

@vlanard
Copy link

vlanard commented Aug 30, 2018

You're right, this is a bug. Thanks for surfacing this @murphd37.

@decmurphy
Copy link

Cool, pull request submitted @ #22

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants