How to get a user's profile picture without Repl Auth

How to get a link to user’s profile picture without Repl Auth using JavaScript?
For example the link to my pfp is here.

I know that once a user is authenticated with Repl Auth, you get access to multiple pieces of information, including a link to their pfp, however I need to get the link without it.

I did see an old post for exactly this here, but I didn’t find any solutions.

import requests
from bs4 import BeautifulSoup
from os import environ

def get_profile_picture_url():
    # Construct the URL of the user's Replit profile page
    profile_url = f"https://replit.com/@{environ['REPL_OWNER']}"

    # Send a GET request to the profile URL and retrieve the HTML content
    response = requests.get(profile_url)
    html_content = response.text

    # Parse the HTML using BeautifulSoup
    soup = BeautifulSoup(html_content, 'html.parser')

    # Find the profile picture HTML element
    profile_picture_element = soup.find('img', {'class': 'avatar-user'})

    if profile_picture_element:
        # Extract the URL from the 'src' attribute of the profile picture element
        profile_picture_url = profile_picture_element['src']
        return profile_picture_url
    else:
        return None

# Usage example
  # Replace with the desired username
profile_picture_url = get_profile_picture_url()

if profile_picture_url:
    print("Profile Picture URL:", profile_picture_url)
else:
    print("Profile picture not found.")

eh I tried this but it never works :skull:
Don’t worry I will try and find this

Oops my bad, I forgot to say that I need to do this in JavaScript.

You can use GraphQL (and PikachuB’s project) to do this:

fetch('https://graphql-playground.pikachub2005.repl.co/', {method: 'POST', body: JSON.stringify({"queries":"query UserByUsername($username: String!) {\n\tuserByUsername(username: $username) {\n    image\n\t}\n}","variables":{"username":"amasad"},"SID":""}), headers: {"Content-Type": "application/json"}})
.then(r => r.json().then(res => {
	/* your code */
}));

(change the username at "variables":{"username":"amasad"} and I set it to amasad)

or directly use it at https://graphql-playground.pikachub2005.repl.co/

or https://replit.com/graphql

3 Likes

Thanks for your reply @doxr, if it’s ok could you please explain how this works step-by-step?

1 Like

For the javascript part I really don’t know as I just used the “Copy as Fetch” and I don’t use Replit’s GraphQL thing that much so I can’t explain that either. I recommend you ask @PikachuB2005 since they made that copy as fetch thing (or anybody else)

Thanks again for the help :grin:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.