The Movie Database Support

My API key works on my local computer but does not work on my production server. Unless I use CURL then it works in both environments. I'm just trying to get a list of movies from the DB. I'm using the URL https://api.themoviedb.org/3/discover/movie?api_key=****

I thought maybe I was using invalid headers, so I used the -I flag on CURL to get the headers and copied them over to my Axios configuration. That still didn't work. I keep getting the error message "Invalid API key: You must be granted a valid key."

6 replies (on page 1 of 1)

Jump to last post

Hi there,

Are you able to enable some logging so you can see the full request(s) that are being made? That will probably help. When it comes to cURL issues, I've often seen a quote problem. For example, this command will not work:

curl http://api.themoviedb.org/3/discover/movie?language=en-US&api_key=###

While this one does:

curl 'http://api.themoviedb.org/3/discover/movie?language=en-US&api_key=###'

CURL works perfectly. My problem is my javascript code only works in a local environment and not in production. When I enable logging in javascript I get the following JSON back on my production server.

{ 
  status_code: 7,
  status_message: 'Invalid API key: You must be granted a valid key.',
  success: false 
}

and I get this response when I run the exact same thing in the local environment.

{ 
  page: 1,
  total_results: 389215,
  total_pages: 19461,
  results: [Array of objects]
}

I double checked to make sure I'm using my API key in my JS code, which I am. Does my website have to be approved?

When I enable logging in javascript I get the following JSON back on my production server.

I need to see something verbose like this (from whichever client is making the request in production):

$ curl -v 'http://api.themoviedb.org/3/discover/movie?language=en-US&api_key=###'
* Trying 50.16.246.113...
* TCP_NODELAY set
* Connected to api.themoviedb.org (50.16.246.113) port 80 (#0)
> GET /3/discover/movie?language=en-US&api_key=### HTTP/1.1
> Host: api.themoviedb.org
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, Retry-After
< Cache-Control: public, max-age=21600
< Content-Type: application/json;charset=utf-8
< Date: Fri, 23 Nov 2018 23:25:00 GMT
< ETag: 1845faa2957cb42b7ddd92b26f114c57
< Server: openresty
< Vary: Accept-Encoding
< Content-Length: 13198
< Connection: keep-alive
<

{"page":1,"total_results":389215,"total_pages":19461,"results":[...]}

Does my website have to be approved?

Nope, we don't do any origin validation.

Ok, I solved the problem. There was a misplaced space in my environment file. That is why it wasn't working on my server. I used CURL in my javascript code and that didn't work so I knew something else was wrong. Thanks for the help either way.

Happy to hear you sorted it out!

How you solve the problem? please elaborate it briefly, I am facing the same issue, invalid API key

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login