Answer the question
In order to leave comments, you need to log in
How to make a request from localhost to VK API?
Situation.
I am using create-react-app.
Created an application on VK, received a token.
Created both Standalone application and website. In the application settings, I registered the addresses of sites localhost: 3000 with and without a port.
I'm trying to make a request:
fetch(`https://api.vk.com/method/users.search?q=${name}&sort=0&count=10&fields=photo_200&v=5.89&access_token=token`);
Access to fetch at ' https://api.vk.com/method/users.search?q=%D0%BC%D0... ' from origin ' localhost:3000 ' 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.
Uncaught (in promise) SyntaxError: Unexpected end of input
Answer the question
In order to leave comments, you need to log in
As this documentation
says :
no-cors - ... In addition, JavaScript may not access any properties of the resulting Response. This ensures that ServiceWorkers do not affect the semantics of the Web and prevents security and privacy issues arising from leaking data across domains.
var script = document.createElement('script');
script.src = "https://api.vk.com/method/getProfiles?uid=66748&access_token=533bacf...&callback=callbackFunc";
document.getElementsByTagName("head")[0].appendChild(script);
function callbackFunc(result) {
console.log(result);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question