In the example below I perform 2 Post Fetch requests. The function 'mdbSetFav' has no cors issues. But the function 'mdbCreateList' has cors issues. Yet the list gets created so I don't understand why I get an error?
mdbCreateList({context},data){
fetch(`${BaseURL}list?api_key=${APIKey}&session_id=${sessionStorage.getItem('sessionID')}`,{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(function(response) {
if (response.status === 401) {
console.log(response)
router.push('/login')
}
return response.text().then(function(text) {
let json = JSON.parse(text)
console.log(json)
return;
})})
.then(function(){
context.dispatch('mdbLists');
})
.catch(function(error){
console.error(error);
});
},
mdbSetFav({state},data){
console.log(JSON.stringify(data))
fetch(`${BaseURL}account/${state.account.id}/favorite?api_key=${APIKey}&session_id=${sessionStorage.getItem('sessionID')} `,{
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(function(response) {
if (response.status === 401) {
console.log(response)
router.push('/login')
}
return response.text().then(function(text) {
let json = JSON.parse(text)
console.log(json)
return;
})})
.then(function(){
//context.dispatch('mdbLists');
})
.catch(function(error){
console.error(error);
});
},
The error:
Access to fetch at 'https://api.themoviedb.org/3/list?api_key=***&session_id=***' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled
and a warning:
Cross-Origin Read Blocking (CORB) blocked cross-origin response https://api.themoviedb.org/3/list?api_key=***&session_id=*** with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
Can anyone help me out?
¿No encuentras una película o serie? Inicia sesión para crearla:
¿Quieres puntuar o añadir este elemento a una lista?
¿No eres miembro?
Contestado por Travis Bell
el 9 de enero de 2019 a las 15:50
Hi @RuneClaeys,
Indeed, it seems as though the
POST /3/list
method does not have the proper CORS headers added. I'll get them added and let you know when it is working.Thanks.
Contestado por RuneClaeys
el 10 de enero de 2019 a las 04:07
Thanks for the quick response. I've come across an other problem. Is it possible that there's an error with the DELETE a list call in version 3 of the API? It keeps telling me I'm not authorized even with a sessionID I just requested?
Contestado por Travis Bell
el 8 de febrero de 2019 a las 16:45
I've created a new ticket that you can follow and vote on about the CORS issue here.
With regards to your second question, have completed step #2 in the walkthrough?
Contestado por kibice
el 27 de junio de 2019 a las 05:00
Hi @travisbell, Could you share roadmap when this fix will be available on production? Thank you in advance.
Contestado por Travis Bell
el 2 de julio de 2019 a las 10:34
Hi @kibice, you can follow the ticket above. That way you will be notified of any changes to it.
Contestado por lawrencemhoni
el 19 de septiembre de 2019 a las 08:01
Hello @travisbell I'm facing the same issue. How do I go about it?
Contestado por Travis Bell
el 20 de septiembre de 2019 a las 18:11
Hey @lawrencemhoni, the fix for this actually went live last week, I just hadn't updated the ticket yet. You can see here there is now the correct headers (
Access-Control-Allow-Origin
) being returned:Request
Response
Contestado por lawrencemhoni
el 21 de septiembre de 2019 a las 12:45
Fantastic! Thank you @travisbell
Contestado por lawrencemhoni
el 21 de septiembre de 2019 a las 13:06
@travisbell for a moment it worked... Maybe I did something right... But right now this is what is being returned.
Contestado por Travis Bell
el 21 de septiembre de 2019 a las 14:43
There's no session ID being specified in your request. You need to pass a approved session in as a
session_id
param.Contestado por lawrencemhoni
el 22 de septiembre de 2019 a las 05:25
@travisbell
returns
Contestado por lawrencemhoni
el 22 de septiembre de 2019 a las 05:28
@travisbell
As shown above, I would love to have my accountID so that I may access my watchlist using
If we can get this to work, you will be my hero of the day.