I'm trying to make an query on the internet game database (IGDB) Api using retrofit. In the past, when I used other Api, such as the movie database (TMDB), the api-keys were always passed in as a query, so the interface would look something like this.
#GET("/3/movie/popular")
Call<MovieResults> getPopularMovie(
#Query("api_key") String apiKey,
#Query("language") String language,
#Query("page") int page
);
But with IGDB, I think they want me to pass in the api-key as a Header (I'm not 100% sure, please correct me if I'm wrong). I've never passed an api-key through a header before, so with some guesswork, following is what my interface looks like.
#Headers({
"Accept: application/json",
"user-key: b5bd50####################8b2"
})
#GET("/games")
Call<List<Game>> getGame();
Problem is, when I make the call, although the call ends up in onResponse, the response.body is always null.
So, I ran the code in de-bug mode, and i found this message:
response = Response{protocol=http/1.1, code=401, message=Unauthorized, url=http://v2000.igdb.com/games/}
I don't know what this means, but I am guessing that it isn't recognizing an authorised api-key?
Another interesting anomaly is that, the base url I pass in is:
"https://api-2445582011268.apicast.io/"
I don't know how that ended up being:
http://v2000.igdb.com/
If anyone have any experience with IGDB, please give me some help, will really appreciate it.
I have used this api with JAVA and i can confirm that you should send the API key in the header, so what you have done looks to be correct.
The base url you are getting is also wrong, try using https://api-endpoint.igdb.com/, it is the recommended url.
I can also recommend you to try the api using Postman, it is an excellent tool for testing.
If you are using java you might want to try their java wrapper
Related
I want to change data on a server via a put request, but I always get a 401 [no body] error. The response looks like the following:
I do not really understand why I get this error, because my body is not empty. My code looks like this and the values seem to be okay too. Does anyone have any idea what I'm doing wrong?
Postman Update:
The values are different right now (consent and authorisation) since its basically a new request but the values were correct before too so this change should not make a difference.
Looks like you are simply passing invalid authorization header, or maybe not passing it at all.
What happens is that you make a RestTemplate exchange call, then you get 401 from that request, and Spring propagates it and returns 500 - Internal Server Error, because there is no error handling in place.
EDIT: According to your screenshots, you are not replacing your path variables. Update the way you build your URL as listed below.
Map<String, String> pathVars = new HashMap<>(2);
pathVars.put("consent-id", consentId);
pathVars.put("authorisation-id", authorisationId);
UriComponents uri = UriComponentsBuilder.fromUri(mainLink)
.path("consents/{consent-id}/authorizations/{authorisation-id}")
.buildAndExpand(pathVars);
Verify if your authorization-id is correct
if the token has a type for example Bearer you must write so:
"Authorization": "Bearer rrdedzfdgf........."
and make sure that there is only one space between Bearer and the token
Often the problem comes from the browser locally;
if your site is online, save the part and deploy the last modifications of the site and make the test
otherwise if it is a mobile application test it on a smartphone and not a browser;
in case none of this works, do it with your backend, it works with this
I had a problem where the I would add an extra character to a password. And Insomnia(Or Postman) would return a JSON response from the server along with a 401 HTTP status code. But when I did the same thing inside a springboot app, when using catch(HttpServerErrorException e){System.out.prinln(e.getMessage());} the e.getMessage would have [no body]. I think that is a feature built in the HttpServerErrorException class where it doesn't provide the body for security purposes. Since whoever is requesting is not authorized they should not have access to it.
I'm using java-play 2.2.1.
I created JS code that send AJAX GET request with a url address that doesn't exist in the conf/routes file. It would be complicated to describe why i don't want to declare this URL at the routes file, so just take it as fact :) .
I catch this request by overriding OnRouteRequest
function (by creating Global object..), and i pull the get params from the request query string (because it's a GET request) and create an object (hashtable) i want to return to the AJAX code at the client-side. Unfortunately, OnRouteRequest function returns Handler.
I'm really desperate right now from this issue, if anyone has any idea how can i do it, it would be really great. Even if anyone knows how to redirect from OnRouteRequest to another action which will return after to the AJAX it would be great. Thanks !
Sorry if this is a duplicate question but google isn't smart enough to understand me or I'm too dumb to express my question simple enough for it to understand.
I don't know if this is my problem but I'm 90% sure this is it.
I'd like to know how to represent a Unix path within a GET request so that my web service doesn't return a 404. I think it's because one of my JSON fields in the query is a Unix path and because of the slashes, the webservice thinks it's part of the URL and not a part of my query.
For example, I'm using a RESTClient that's an add-on to Mozilla to test my web service. For the POST request, I enter as the url
http://mytestserver:8080/mydir/
and in the body, I put in my JSON object
{"filename":"obit.jpg", "Path":"test/2/1"}
This method works fine. I get a status code 200 and a return JSON object with the expected output.
When I use the same string for a GET request, I get a status code 404 and no return JSON object. I put as the url in the RESTClient
http://mytestserver:8080/mydir/{"filename":"obit.jpg", "Path":"test/2/1"}
and I get a status code 404 and the response body just says 404 - Not found
To further test my theory, I entered the following url in a GET request, removing the /2/1 from the path, which works.
http://mytestserver:8080/mydir/{"filename":"obit.jpg", "Path":"test"}
I've tried encapsulating the whole JSON string in quotes but that didn't work either so I've run out of things to try.
Thanks in advance for any help you can give me. If I need to show some code, please let me know, although, I don't think it's a code problem, I think it's a representation problem. Thanks.
Found out that JSON objects are usually sent via POST, not GET. Since I appended it to the URL via GET, it gave me problems. Per How to send a GET request with a "/" in the query
When i am trying to get data from facebook using graph api, i am getting this error,
{"error":
{"message":"(#803) Some of the aliases you requested do not exist: 124186682456_10151302011177457&access_token=REMOVED_ACCESS_TOKEN",
"type":"OAuthException",
"code":803}}
Can anyone help me in how to solve this problem.
Thanks in advance...
If that is an accurate representation of the error you're receiving, you're incorrectly appending the access token after a & character instead of a ?.
You need to use ? for the start of the query string, and & to separate the parameters inside the query string
e.g.
https://graph.facebook.com/124186682456_10151302011177457?access_token=ACCESS_TOKEN
Placement of access_token parameter immediately after ? has nothing to do with issue...
It could be that your URL is littered with %20 or similar stuff.
I got this error when trying a test example from Facebook API documentation, at first I have read highest voted answer, but moving access_token parameter immediately after ? didn't work, I then inspected URL more closely and found some of encoded spaces %20 that were stuck to parameter fields and some others, removing which fixed the issue.
try following URL (just replace access_token parameter with yours)
https://graph.facebook.com/search?type=place&fields=name,checkins,picture&q=cafe¢er=40.7304,-73.9921&distance=1000&access_token=[YOUR_ACCESS_TOKEN]
If it works look for problem in Facebook parameter names
Hope this saves you some time.
This was happening for me with the Instagram content publishing API which also rides off the facebook graph api. It seems to happen when something is wrong with the API URL you are trying to send to Facebook via GET request.
In my case, something was happening in my code causing the user_id and access_token to not be passed to the URL before trying to query the graph API.
First off, I'm using an older version of Restlet (1.1).
Secondly, I'm not sure I'm doing the correct thing. Here's what I'm trying to do...
I'm creating a reporting service (resource). I'd like my service to listen for POST requests. The body of the request will contain the report definition. I'd like the response to be the CSV file generated by the service (the report). Is responding to a POST request in this manner OK from a REST standpoint (if not, then how to refine this resource)?
I can't seem to figure out how the acceptRepresentation() generates the response. I've tried setting the Representation parameter passed into the method to a new FileRepresentation. I've also tried to utilize the represent() method, but it doesn't seem like that method is called as part of the POST processing.
How can I accomplish this seeming easy task?
Calling the getResponse().setEntity() method from acceptRepresentation() will accept the new FileRepresentation and accomplish what I'd like to.