这里的Foursquare现在来自data.response.checkins?

时间:2014-03-04 20:32:30

标签: javascript json api foursquare

我试图通过对特定用户的checkins查询从FourSquare获取hereNow参数,不幸的是我似乎无法使用checkins获取该参数,我看到除了hereNow参数之外的所有其他数据。

有谁知道如何使用签到我的参数?否则,我如何将场地对象合并到我当前的代码中?

以下是我在此处设置的JavaScript现在作为变量:

var count;
getVenueStatus = function() {
    var hereNowUrl = 'https://api.foursquare.com/v2/venues/VENUE_ID?&oauth_token=OAUTH_TOKEN&v=20140303';
    $.getJSON(hereNowUrl, {format: "json"}, function(data) {
        $(data.response.venue).each(function(index) {
            $(this).each(function(index) {
                var venue = this;
                var hereNowCount = venue.hereNow.count;
                count = hereNowCount;
                console.log(count);
            });
        });
    });
}

以下是我在地图上显示结果的JavaScript:

findFoodTrucks = function (param) {
        getVenueStatus();
        $.mobile.pageLoading();
        var url = 'https://api.foursquare.com/v2/users/80507329/checkins?oauth_token=OAUTH_TOKEN&v=20140303';
        var mapBounds = new google.maps.LatLngBounds();
        if (param.userloc) mapBounds.extend(param.userloc);
        $.getJSON(url, function(data) {
                $(data.response.checkins).each(function(index) { // groups: nearby, trending
                    $(this.items).each(function(index) {
                        var foodtruck = this;
                        var foodtruckPosition = new google.maps.LatLng(foodtruck.venue.location.lat, foodtruck.venue.location.lng);
                        var foodtruckIcon = (count > 0) ? 'foodtruck_active.png' : 'foodtruck_inactive.png';
                        var foodtruckStreet = (foodtruck.venue.location.address) ? '<br>' + foodtruck.venue.location.address : '';
                        var foodtruckContent = '<a href="https://foursquare.com/venue/' + foodtruck.venue.id + '"><strong>' + foodtruck.venue.name + '</strong></a>' + foodtruckStreet + '<br>';
                        mapBounds.extend(foodtruckPosition);
                        addFoodTruckMarker(foodtruckPosition, foodtruckIcon, foodtruckContent);
                        console.log(foodtruck);
                    });
                    if (param.zoomtotrucks) $('#map_canvas').gmap('getMap').fitBounds(mapBounds);
                });
        })
        .error( function() { 
            loadFoodTrucks(param); //try again
        })
        .complete( function() { 
            $.mobile.pageLoading( true ); 
        });
    }

提前致谢!

1 个答案:

答案 0 :(得分:0)

check-in response包含compact venue,有时只保证hereNow字段。要获得hereNow计数,最好进行第二次venue detail API调用。

PS:还注意到您似乎传递了OAuth令牌客户端ID /机密 - 在这种情况下,您只需要OAuth令牌!请查看https://developer.foursquare.com/overview/auth以获取更多信息。