Esempio n. 1
0
def refresh_access_token():
    cursor,conn = common_unit.database_connection()
    get_refresh_token_list_query = 'SELECT seller_id,secret_key,refresh_token FROM store WHERE website = "35"'
    cursor.execute(get_refresh_token_list_query)
    wish_refresh_token_list = cursor.fetchall()
    conn.close()
    count = 0
    for token_line in wish_refresh_token_list:
        result = refresh_execute(token_line)
        count += result[0]
        if result[1] != 0:
            common_unit.write_log(result[1])
    return 0
Esempio n. 2
0
def refresh_execute(token_line):
    try:
        url = 'https://merchant.wish.com/api/v2/oauth/refresh_token?client_id=%s&client_secret=%s&refresh_token=%s&grant_type=refresh_token'%token_line
        r = requests.post(url)
        result_data = json.loads(r.text)['data']
        common_unit.write_log(r.text)
        cursor,conn = common_unit.database_connection()
        update_token_query = 'UPDATE store SET mws_token = "%s",refresh_token="%s" WHERE seller_id = "%s"'%(result_data["access_token"],result_data["refresh_token"],result_data["client_id"])
        cursor.execute(update_token_query)
        conn.commit()
        cursor.close()
        return (0,0)
    except (Exception) as e:
        return (1,str(e))