在React Native android上的Back4App中,在fetch api中出现未经授权的错误。

问题描述 投票:0回答:1

我正试图访问 公共数据库back4app. 我正在使用react-native并试图访问下面的API代码。

const where = encodeURIComponent(JSON.stringify({
    "postalCode": postalCode
}));
const response = await fetch(
    `https://parseapi.back4app.com/classes/IN?limit=10&where=${where}`,
    {
        headers: {
            'X-Parse-Application-Id': Constants.BACK4APP_API_KEY, // This is actual Application Id
            'X-Parse-Master-Key': Constants.BACK4APP_REST_API_KEY, // This is actual App Master Key

        }
    }
);
const data = await response.json();

我尝试使用 Javascript键, 客户密钥, .NET键, REST API密钥 但它总是给 unauthorized 对我来说是错误的。当我用 主密钥 测试(Back4App不推荐),没有错误,但返回的是空结果,用Sample API KEY进行同样的查询,返回的是数据。

有谁能帮忙吗?

react-native-android back4app
1个回答
0
投票

我得到了Back4App支持团队的帮助。然后再主键头。rest api key 运作良好。

const where = encodeURIComponent(JSON.stringify({
    "postalCode": postalCode
}));
const response = await fetch(
    `https://parseapi.back4app.com/classes/IN?limit=10&where=${where}`,
    {
        headers: {
            'dataType': 'json',
            'X-Parse-Application-Id': Constants.BACK4APP_API_KEY, 
            'X-Parse-REST-API-Key': Constants.BACK4APP_REST_API_KEY,
            'Content-Type': 'application/json' 
        }
    }
);
const data = await response.json();
© www.soinside.com 2019 - 2024. All rights reserved.