gpt4 book ai didi

javascript - 无用户身份验证 Foursquare API "Missing access credentials"- 400 错误

转载 作者:行者123 更新时间:2023-12-03 01:44:39 25 4
gpt4 key购买 nike

有点奇怪。我正在构建一个与 Foursquare API 交互的 React js 应用程序,主要是为了了解 React js 和 API。

我正在使用 Foursquare 来获取 field 信息,效果很好。我还想用它来获取 field 照片,这就是乐趣的开始。

处理原始调用 field 的方法如下。我只是把它放在这里是为了提供一个控制,因为它工作得很好。它返回我在应用程序中处理的 field 信息,没有任何问题:

getVenues: (searchTerm) => {

const urlToFetch =

${urlExplore}${searchTerm}&limit=10&client_id=${clientId}&client_secret=${clientSecret}&v=20180602;

    return fetch(urlToFetch).then( response => {
return response.json();
}).then( jsonResponse => {
if (jsonResponse.response.groups[0].items) {
return jsonResponse.response.groups[0].items.map(item => (
{
id: item.venue.id,
name: item.venue.name,
// blah
}
));

} else {
return [];
}

})

}

到目前为止,一切顺利,运行良好。但是,当我尝试使用相同的方法访问照片端点时,该方法返回一系列包含元的对象,其中表示:

​代码:400​​ errorDetail:“缺少访问凭据。请参阅 https://developer.foursquare.com/docs/api/configuration/authentication为了 细节。” ​​错误类型:“invalid_auth”

足以说所提供的链接中的信息实际上并没有提供太多帮助:-(

我用来获取照片信息的方法是:

getVenuePhotos: (venueId) => {

const fetchPhotosURL = `${urlPhotos}${venueId}/photos&limit=10&client_id=${clientId}&client_secret=${clientSecret}&v=20180602`;

return fetch(fetchPhotosURL).then( response => {
return response.json();
}).then( jsonResponse => {
console.log(jsonResponse);
//blah - removed to save space - see method above, it's pretty much the same
})

}

...两者都存储在 react 组件导入的单独文件中的对象中。

url 变量解析如下(星号是我添加的):

fetchVenuesURL: https://api.foursquare.com/v2/venues/explore?near=london&limit=10&client_id=**** &client_secret=****&v=20180602

fetchPhotosURL: https://api.foursquare.com/v2/venues/4ac518eff964a52064ad20e3/photos&limit=10&client_id=**** &client_secret=****&v=20180602

有人知道为什么会发生这种情况吗?

提前致谢

最佳答案

我认为您的网址中有拼写错误。

替换

${urlPhotos}${venueId}/photos&limit=10&client...

${urlPhotos}${venueId}/photos?limit=10&client...

关于javascript - 无用户身份验证 Foursquare API "Missing access credentials"- 400 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50695096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com