我的 foursquare api 调用有什么问题?

What is wrong with my foursquare api call?

实例在这里 http://kenziejoy.github.io/frontend-nanodegree-map/

我正在尝试提取有关我在数组中硬编码的位置的数据 - 通过它们的四方 ID(似乎不起作用)或它们的纬度和经度。 (客户端 ID 和密码是变量,我只是没有在这里显示)

除了从他们的数据库中提取数据以显示在地图上之外,我不需要任何其他功能,所以我认为它会属于无用户访问权限,但它给我一个错误请求是错误的,因为我不知道' 有适当的身份验证。

提前致谢

来自四方网站 "无用户访问

我们的一些不属于特定用户信息的端点(例如场所搜索)启用了无用户访问(这意味着您不需要让用户授权您的应用程序进行访问)。要发出无用户请求,请在请求中指定您的消费者密钥的客户端 ID 和机密,而不是身份验证令牌 URL。

https://api.foursquare.com/v2/venues/search?ll=40.7,-74&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&v=YYYYMMDD

要查看每个端点需要什么级别的权限,请查看我们端点页面顶部的过滤器。“

        /**********FourSquare***************/
    $.ajax({
        url:'https://api.foursquare.com/v2/venues/search',
        dataType: 'json',
        data: 'limit=1' +
                '&ll='+ placeItem.lat() +','+ placeItem.lng() +
                '&?client_id='+ CLIENT_ID +
                '&client_secret='+ CLIENT_SECRET +
                '&v=20140806' +
                '&m=foursquare',
        async: true,

        success: function (data) {
            var result = data.response.venue;
            var contact = result.hasOwnProperty('contact') ? result.contact : '';
            if (contact.hasOwnProperty('formattedPhone')) {
                placeItem.phone(contact.formattedPhone || '');
            }

            var location = result.hasOwnProperty('location') ? result.location : '';
            if (location.hasOwnProperty('address')) {
                placeItem.address(location.address || '');
            }

            var bestPhoto = result.hasOwnProperty('bestPhoto') ? result.bestPhoto : '';
            if (bestPhoto.hasOwnProperty('prefix')) {
                placeItem.photoPrefix(bestPhoto.prefix || '');
            }

            if (bestPhoto.hasOwnProperty('suffix')) {
                placeItem.photoSuffix(bestPhoto.suffix || '');
            }

            var description = result.hasOwnProperty('description') ? result.description : '';
            placeItem.description(description || '');

            var rating = result.hasOwnProperty('rating') ? result.rating : '';
            placeItem.rating(rating || 'none');

            var url = result.hasOwnProperty('url') ? result.url : '';
            placeItem.url(url || '');

            placeItem.canonicalUrl(result.canonicalUrl);

            // Infowindow code is in the success function so that the error message

            // Content of the infowindow
            var contentString = '<div id="iWindow"><h4>' + placeItem.name() + '</h4><div id="pic"><img src="' +
                    placeItem.photoPrefix() + '110x110' + placeItem.photoSuffix() +
                    '" alt="Image Location"></div><p>Information from Foursquare:</p><p>' +
                    placeItem.phone() + '</p><p>' + placeItem.address() + '</p><p>' +
                    placeItem.description() + '</p><p>Rating: ' + placeItem.rating() +
                    '</p><p><a href=' + placeItem.url() + '>' + placeItem.url() +
                    '</a></p><p><a target="_blank" href=' + placeItem.canonicalUrl() +
                    '>Foursquare Page</a></p><p><a target="_blank" href=https://www.google.com/maps/dir/Current+Location/' +
                    placeItem.lat() + ',' + placeItem.lng() + '>Directions</a></p></div>';

            // Add infowindows
                google.maps.event.addListener(placeItem.marker, 'click', function () {
                infowindow.open(map, this);
                // Bounce animation
                placeItem.marker.setAnimation(google.maps.Animation.BOUNCE);
                setTimeout(function () {
                    placeItem.marker.setAnimation(null);
                }, 800);
                infowindow.setContent(contentString);
            });
    },

        // Alert the user on error.
        error: function (e) {
            infowindow.setContent('<h5>Foursquare data is unavailable.</h5>');
            document.getElementById("error").innerHTML = "<h4>Foursquare data is unavailable. Please try refreshing.</h4>";
    }
    });

我查看了实际示例 URL,您在 Chrome 的 JavaScript 控制台中遇到了很多错误的请求错误。

看着这些,你的表现很糟糕 URL,你正在使用:

https://api.foursquare.com/v2/venues/search?limit=1&ll=45.5589522,-122.6517163&?client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&v=20140806&m=foursquare

问题似乎是你有:

 &?client_id

这使得 URL 无效。

将其更改为

 &client_id

解决了这个问题,然后我看到了从 Foursquare 返回的数据。