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
Trying to get follower count for a user but its not working #302
Comments
Hey, there! API V1 has been deprecated, you should use v2 instead. |
Is there any example code around for getting an output from api v2? In any language? Trying to use the api v2. But it's always returning 403 or 404. update the code with v2 api: import json
import urllib.request
import ssl
# Prompt the user to enter their developer token
developer_token = input("Enter your Product Hunt developer token: ")
# Replace YOUR_DEVELOPER_TOKEN with the developer token in the headers dictionary
headers = {"Accept": "application/json", "Content-Type": "application/json", "Authorization": f"Bearer {developer_token}"}
# Prompt the user to enter a Product Hunt username
username = input("Enter a Product Hunt username: ")
url = f"https://api.producthunt.com/v2/users/{username}?user.fields=follower_count"
# Create an SSL context to ignore SSL certificate errors
context = ssl.create_default_context()
context.check_hostname = False
context.verify_mode = ssl.CERT_NONE
# Create a request object with the URL and headers
req = urllib.request.Request(url, headers=headers)
# Make an HTTP GET request to the URL
response = urllib.request.urlopen(req, context=context)
if response.status == 200:
# Read the response and decode it as JSON
data = response.read().decode("utf-8")
json_data = json.loads(data)
follower_count = json_data["user"]["follower_count"]
print(f"{username} has {follower_count} followers on Product Hunt.")
else:
print("Error:", response.status) error:
|
Im trying the grapnQL api instead. but still 403: import json
import urllib.request
import ssl
# Prompt the user to enter their developer token
developer_token = input("Enter your Product Hunt developer token: ")
# Set the headers with the developer token
headers = {"Accept": "application/json", "Content-Type": "application/json", "Authorization": f"Bearer {developer_token}"}
# Prompt the user to enter a Product Hunt username
username = input("Enter a Product Hunt username: ")
# Define the GraphQL query
query = """
query getUser($username: String!) {
user(username: $username) {
followerCount
}
}
"""
# Set the variables for the query
variables = {"username": username}
# Set the GraphQL request data
data = {"query": query, "variables": variables}
# Encode the data as JSON
data_json = json.dumps(data).encode("utf-8")
# Set the GraphQL request URL
url = "https://api.producthunt.com/v2/api/graphql"
# Create the GraphQL request
req = urllib.request.Request(url, data=data_json, headers=headers)
# Send the GraphQL request with SSL certificate verification disabled
with urllib.request.urlopen(req, context=ssl._create_unverified_context()) as response:
if response.status == 200:
# Decode the response as JSON
json_data = json.loads(response.read().decode("utf-8"))
follower_count = json_data["data"]["user"]["followerCount"]
print(f"{username} has {follower_count} followers on Product Hunt.")
else:
print("Error:", response.status) error:
GPT interpretation of the error:
|
Getting 403 if I try to use API key and API secret as well. So it might not be the Developer token |
Have you sovled this? I have this issue too |
Nope. Never figured it out. |
Ip is causing the problem for me, even though I haven't don web crawling. Anyway change the IP solve the 403 error for me. |
I created a dev token for my account. (I didn't know what to put in the redirect url, so I just added producthunt.com)
Here is my test:
and here is the error message:
Here is what GPT is telling me is wrong:
The text was updated successfully, but these errors were encountered: