我最近限制了一个API键来接受来自特定网站的请求,但我使用了来自Firebase云功能的相同api键来进行地点搜索。
我应该为云功能请求添加什么url?
Url是这样构建的
const urlFindPlaceFromText = "https://maps.googleapis.com/maps/api/place/findplacefromtext";
const fields = "formatted_address,name,geometry,icon,rating,price_level,place_id";
const location = "point:$latitude, $longitude";
const url = `${urlFindPlaceFromText}/json?input=${searchString}&inputtype=textquery&language=en&fields=${fields}&locationbias=${location}&key=${apiKey}`;
const placesRequest = await axios.get(url)
回应:
data: {
> candidates: [],
> error_message: 'API keys with referer restrictions cannot be used with this API.',
> status: 'REQUEST_DENIED'
> }
1条答案
按热度按时间0dxa2lsx1#
您看到的错误看起来像是您在服务器端进行API呼叫。因为您已在API密钥上设定参照者限制,它将限制为在具有Web服务API的浏览器上执行。如上述注解所述,您可以建立个别的密钥来使用服务器端。您可以使用IP位址来限制存取,将限制从浏览器限制变更为服务器限制。而不是浏览器引用。
有关将密钥类型切换为服务器受限密钥的信息,请查看此API常见问题解答
有关详细信息,请查看以下类似示例: