Привет!
Мне нужно отправить пользователю ВК сообщение от имени сообщества. Нашел разные реализации, но выдает ошибку:
Failed to load https://api.vk.com/method/messages.send: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'XXXX.ru' is therefore not allowed access. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
let token = 'XXXX';
let user_id = 99999;
let message = 'msg';
let apiMsg = 'https://api.vk.com/method/messages.send';
let header = new Headers({
'Access-Control-Allow-Origin':'*',
'Content-Type': 'multipart/form-data'
})
let data = {
'user_id': user_id,
'message': message,
'access_token': token
};
let options = {
mode: 'cors',
header: header,
'method': 'post',
'payload': data
};
fetch(apiMsg, options)
.then((data) => {
return data.text()
})
.then((text) => {
console.log(text)
})
.catch((error) => {
console.log('There has been a problem with your fetch operation: ' + error.message)
})
Почему возникает ошибка, я же добил Access-Control-Allow-Origin? Как правильно?