请在Google API控制台中确认已经使用了正确的API Key,并且设置了正确的权限和限制。
从控制台中获取Google API v3的请求URL,并检查其中的参数是否填写正确。如果没有填写正确的参数,Google API返回的数据也有可能是加密的。
如果确认请求URL和API Key没有问题,但是返回的数据仍然是加密的,那么可能需要对数据进行解密。解密方法可能因接口不同而不同,请根据具体情况自行尝试解密方法。
以下是使用Axios请求Google Places API并获取查询结果的示例代码:
const axios = require('axios');
const API_KEY = 'YOUR_API_KEY';
const PLACE_URL = 'https://maps.googleapis.com/maps/api/place/findplacefromtext/json';
const getPlaces = async (query) => {
const response = await axios.get(PLACE_URL, {
params: {
input: query,
inputtype: 'textquery',
key: API_KEY
}
});
return response.data.candidates;
};
在此示例中,请替换“YOUR_API_KEY”为您自己的Google API Key。可以通过调用“getPlaces”函数并传入需要查询的地点名称来获取查询结果。