I am trying to get the hereNow parameter from FourSquare using a checkins query on a specific user, unfrotunately I can't seem to get that parameter using checkins, I am seeing all other data regarding a venue except for the hereNow parameter.

Does anyone know how I can get that parameter using checkins? Otherwise, how can I incorporate venue objects and tie into my current code?

Here is my JavaScript to set hereNow as a variable:

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);
            });
        });
    });
}

Here is my JavaScript to display the results on a map:

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 ); 
        });
    }

Thanks in advance!

有帮助吗?

解决方案

The check-in response includes a compact venue, which is only sometimes guaranteed to have a hereNow field. To get the hereNow count, it's probably best to make a second venue detail API call.

PS: also noticed that you seemed to be passing an OAuth token and client ID/secret—in this case, you only need the OAuth token! Take a look at https://developer.foursquare.com/overview/auth for more info.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top