I'm currently looking to use ProductHunt's API (https://api.producthunt.com/v1/docs) to make simple get requests. Their API requires a token and a redirect URI. When I try to access their posts and apply the ApiKey I've been given along with a URI, I'm redirected to the URI but not given a JSON object. What would a getJSON or AJAX request therefore look like?
In my browser,when I try to make a simple request to their JSON, I get a bunch of bad responses. As it is, I'm simply trying to retrieve their JSON to access posts but am unsure how to construct a URL to retrieve this without getting redirected.
Here is what I have as a simple request so far:
var query_params = { client_id:'[my apikey]' ,
response_type:'code',
redirect_uri:'[my URI]',
scope:'public+private',
};
$.ajax({
url:'https://api.producthunt.com/v1/posts',
type:'GET',
data:query_params,
crossDomain:true,
dataType:'jsonp',
success:function(data){
console.log(data)
},
error:function(){
console.log('Failed!');
}
});
What would the request URL look like to be able to access their JSON object? Also what am I missing in the code above? Thanks for any help on this matter.
I'm consuming Product Hunt API in Python, I guess the request is pretty much the same.
You are missing an header with your access token
headers = {'Accept':'application/json',
'Content-Type':'application/json',
'Authorization': 'Bearer '+acess_token,
'Host':'api.producthunt.com'}
try to add this to your get request, it should return a valid JSON