Axuda de The Movie Database

I created a new api key and it's still not reading on my react project. Here is the code, any help would be appreciated. I have a .env file where the token and key are. Am i missing something?

const Add = () => { const [query, setQuery] = useState(""); const onChange = e => { e.preventDefault();

setQuery(e.target.value);

const options = {
  method: 'GET',
  headers: {
    accept: 'application/json',
    Authorization: `Bearer ${process.env.REACT_APP_ACCESS_TOKEN}`

  },
};


fetch(`https://api.themoviedb.org/3/search/tv?api_key=${process.env.REACT_APP_TMDB_KEY}&language=en-US&page=1&include_adult=false&query=${e.target.value}`
).then (res => res.json())
.then(data => {
  console.log(data)
})

};??

4 respostas (na páxina 1 de 1)

Jump to last post

I updated the fetch to call the options in it and still nothing.

hi @derek12345, you should print (console.log()) the string you are trying to fetch to see if there is anything wrong with it. If the api_key is missing, then read this:

https://stackoverflow.com/questions/49579028/adding-an-env-file-to-a-react-project

https://stackoverflow.com/questions/48378337/create-react-app-not-picking-up-env-files

Remove the env file and add key to code it works and I am also getting same error when using env file

Hi @Mohit1310,

Remove the env file and add key to code it works and I am also getting same error when using env file

If this is the case then you need to review the two stackoverflow links above that discuss issues with reading from an env file.

Non podes atopar unha película ou serie? Inicia sesión para creala.

Global

s amosar a barra de procura
p abrir menú do perfil
esc pechar e abrir xanela
? abrir xanela de atallos do teclado

En páxinas de medios

b atrás (ou á principal se aplica)
e ir a editar páxina

En páxinas de tempadas de televisión

(flecha dereita) ir á tempada seguinte
(flecha esquerda) ir á tempada anterior

En páxinas de episodios de televisión

(flecha dereita) ir ao episodio seguinte
(flecha esquerda) ir ao episodio anterior

En todas as páxinas de imaxe

a abrir a xanela de engadir imaxe

En todas as páxinas de edición

t abrir selector de traducións
ctrl+ s enviar formulario

Nas páxinas de debate

n crear un novo debate
w amosar o estado do seguimento
p mudar público/privado
c mudar abrir/pechar
a abrir actividade
r responder no debate
l ir á última resposta
ctrl+ enter eviar a túa mensaxe
(flecha dereita) páxina seguinte
(flecha esquerda) ir á páxina anterior

Configuración

Queres valorar ou engadir o elemento a unha listaxe?

Iniciar sesión