【问题标题】:Userless Authentication Foursquare API "Missing access credentials" - 400 error无用户身份验证 Foursquare API“缺少访问凭据”- 400 错误
【发布时间】:2018-06-05 16:26:21
【问题描述】:

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

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

处理对场地的原始呼叫的方法如下。我只是把它放在这里是为了提供一个控件,因为它工作正常。它会毫无问题地返回我在应用程序中处理的场地信息:

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 [];
        }

    })

}

到目前为止,一切都很好,效果很好。但是,当我尝试使用相同的方法访问照片端点时,该方法返回一系列包含 meta 的对象:

​代码:400 ​​ errorDetail:“缺少访问凭据。请参阅 https://developer.foursquare.com/docs/api/configuration/authentication 为 细节。” ​​errorType: "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

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

提前致谢

【问题讨论】:

    标签: javascript reactjs authentication es6-promise foursquare


    【解决方案1】:

    我认为您的网址中有错字。

    替换

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

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

    【讨论】:

    • 我完全错过了。说我觉得有点傻是轻描淡写的。嗬!谢谢你告诉我:-)
    猜你喜欢
    • 1970-01-01
    • 2015-06-01
    • 1970-01-01
    • 2014-01-05
    • 2021-09-24
    • 2014-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多