You might want to get BitClout user information for your next project, right ?
If yes, you are on the right page of the Internet!
We will be covering two BitClout API endpoints that provides user information including username, coin price, profile photo and other tons of information about any user.
To use the endpoints, you only need a prior knowledge of dealing with GET or POST requests. Since the article shows working code in python, it is must that you know some basic python atleast.
Of course you can use your desired language to do your task since it is only the game of GET and POST requests.
Let's get started!
- The first and most preferred way to get user information is through "Public Key" of a user.
The
get-user-stateless
endpoint returns a gigantic data in JSON format! Here is a working code of the endpoint:
import requests
import json
def getUserStateless(listOfPublicKeys): #the method takes List of PublicKey(s)
endpoint = "https://api.bitclout.com/get-users-stateless"
payload = {"PublicKeysBase58Check": listOfPublicKeys}
response = requests.post(endpoint, json = payload)
file = open("userData.json", "w") #the response data will be saved in file "userData.json"
json.dump(response.json(), file)
file.close()
return response.status_code #returning response code. 200 means successful !
if __name__ == "__main__":
listOfPublicKeys = ["BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"] #you can add more public keys in this list
print(getUserStateless(listOfPublicKeyss)
The above code dumps the data returned by the endpoint in json file.
You can study the file "userData.json" to better understand the data.
You might want to see metrices like coin price etc. but for that you will have to do some basic calculations.
For example, if you want to get the coin price of the user, you will have to divide the CoinPriceBitCloutNanos
by 1,000,000,000 and then multiply the resultant with the current price of BitClout in USD. In order to get the current price of BitClout, refer to this article.
The endpoint returns more than just a coin price. You can study the userData.json file to learn more!
- The
get-user-stateless
returns gigantic data about the user but in some cases you might want to get only general information about the user like coin price, username, description, profile picture etc. That's where theget-single-profile
endpoints come handy! Below is working python code to use theget-single-profile
endpoint:
import requests
import json
def getSingleProfile(publicKey):
payload= {"PublicKeyBase58Check":publicKey,"Username":""}
response = requests.post(url="https://api.bitclout.com/get-single-profile", json=payload)
file = open("singleProfile.json", "w")
json.dump(response.json(), file)
file.close()
return response.status_code
if __name__ == "__main__":
publicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(getSingleProfile(publicKey))
If the above code prints the status code 200, you will see a new file created in your working directory named "singleProfile.json" that has general information about the user. Be a geek and study it!
The above mentioned two endpoints accept public key of BitClout user to fetch the data but what if you want to get information of a user through user name ? Well, there is a way to do that!
You can simply use the get-single-profile
to get the user information by passing the username only.
Here is a working python code to get general information of a user through username:
import json
import requests
def getInfoByUsername(username):
payload = {"PublicKeysBase58Check": [""],
"Username": username}
response = requests.post(url="https://api.bitclout.com/get-single-profile", json=payload)
file = open("getUserByName.json", "w")
json.dump(response.json(), file)
file.close()
return response.status_code
if __name__ == "__main__":
username = "ItsAditya"
print(getInfoByUsername(username))
If the above code prints status code 200, you will see a new file created named "getUserByName.json" that has all the general information about that user.
Now it's totally your choice to get the information through public key or through username.
It must be noted that public key of a user is a constant entity which never changes while a username can be changed so it's a good practice to fetch the data through the public key.
If you like the article don't forget to let us know in the comments or maybe give a shout to DevsClout ? You can also join DevsClout discord server to chat with more devs who are building awesome projects on BitClout! We would love to hear back from you!
Top comments (0)