无用户身份验证 Foursquare API "Missing access credentials" - 400 错误
Userless Authentication Foursquare API "Missing access credentials" - 400 error
有点奇怪。我正在构建一个与 Foursquare API 交互的 React js 应用程序,主要是为了了解 React js 和 APIs。
我正在使用 Foursquare 获取场地信息,效果很好。我也想用它来获取场地照片,这就是乐趣的开始。
原来调用会场的处理方法如下。我只是把它放在这里是为了提供一个控制,因为它工作正常。它 returns 我在应用程序中处理的场地信息没有问题:
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 [];
}
})
}
到目前为止,还不错,工作正常。但是,当我尝试使用相同的方法访问照片端点时,方法 returns 一系列包含元的对象表示:
代码:400
errorDetail:“缺少访问凭据。请参阅
https://developer.foursquare.com/docs/api/configuration/authentication 为
细节。”
错误类型:"invalid_auth"
可以说 link 提供的信息实际上并没有提供太多帮助:-(
我使用的获取照片信息的方法是:
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
})
}
...两者都存储在反应组件导入的单独文件中的对象中。
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
有人知道为什么会这样吗?
提前致谢
我认为您的 URL 中有错字。
替换
${urlPhotos}${venueId}/photos&limit=10&client...
和
${urlPhotos}${venueId}/photos?limit=10&client...
有点奇怪。我正在构建一个与 Foursquare API 交互的 React js 应用程序,主要是为了了解 React js 和 APIs。
我正在使用 Foursquare 获取场地信息,效果很好。我也想用它来获取场地照片,这就是乐趣的开始。
原来调用会场的处理方法如下。我只是把它放在这里是为了提供一个控制,因为它工作正常。它 returns 我在应用程序中处理的场地信息没有问题:
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 [];
}
})
}
到目前为止,还不错,工作正常。但是,当我尝试使用相同的方法访问照片端点时,方法 returns 一系列包含元的对象表示:
代码:400 errorDetail:“缺少访问凭据。请参阅 https://developer.foursquare.com/docs/api/configuration/authentication 为 细节。” 错误类型:"invalid_auth"
可以说 link 提供的信息实际上并没有提供太多帮助:-(
我使用的获取照片信息的方法是:
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
})
}
...两者都存储在反应组件导入的单独文件中的对象中。
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
有人知道为什么会这样吗?
提前致谢
我认为您的 URL 中有错字。
替换
${urlPhotos}${venueId}/photos&limit=10&client...
和
${urlPhotos}${venueId}/photos?limit=10&client...