deviantart icon indicating copy to clipboard operation
deviantart copied to clipboard

Error 400 when I try to authorize with my stored request token?

Open theothersophie opened this issue 7 years ago • 1 comments

The following code is giving me Error: HTTP Error 400: Bad Request and I don't understand why (client and token replaced for obvious reasons). I saved the refresh token from a successfully authorized session yesterday and can't seem to figure out how to obtain a new access token from it. How do I do it?

import deviantart

client_id = 'CLIENT_ID_HERE'
client_secret = 'CLIENT_SECRET_HERE'

da = deviantart.Api(
    client_id,
    client_secret,

    redirect_uri="REDIRECT_URI_HERE",
    standard_grant_type="authorization_code",
)

refresh_token = 'REFRESH_TOKEN_HERE'

# PROBLEM HERE
try:
    da.auth(refresh_token = refresh_token)
except deviantart.api.DeviantartError as e:
    print ("Couldn't authorize user. Error: {}".format(e))

if da.access_token:

    print ("The access token {}.".format(da.access_token))
    print ("The refresh token {}.".format(da.refresh_token))

    #the User object of the authorized user
    user = da.get_user()

    print ("The name of the authorized user is {}.".format(user.username))

theothersophie avatar Jan 30 '18 02:01 theothersophie

I hope this provides some useful insight: https://www.deviantart.com/developers/authentication

Refreshing An Access Token

All access_token's expire after one hour, after expiration you either need to re-authorize the app or refresh your access token using the refresh_token from the /token request.

The refresh_token will expire after 3 months, after that time you must re-authorize the app.

PeterJRiches avatar Aug 24 '20 05:08 PeterJRiches