简体   繁体   中英

Meetup API - listing events by category, within a distance from lat/lng - Javascript

I'm creating a web app that makes a front-end javascript request to the Meetup API to get a list of events, the query will be generated dynamically with the users lat/lng, specified distance, and a category id of 34 (tech).

Having real problems figuring this out been at it for hours the API documentation is poor - I can get a list of events within a specified distance (2 miles in this example) from lat/lng:

https://api.meetup.com/find/events?photo-host=public&sig_id=my_id&radius=2&lon=-3.1883&lat=55.9533&sig=my_api_key

but I can't figure out how to list only those events with category 34.

Can this be done on on the client side - is it possible?

Any help would be much appreciated, thanks.

It looks like you have to add to fields the field group_category . Then in your response you can filter out group categories with the id of 34 . Here is an example that I got back:

"10": {
  "created": 1476031548000,
  "duration": 25200000,
  "id": "pqnnbmywhblc",
  "name": "The Sunday Hack Shack WorkShop",
  "status": "upcoming",
  "time": 1495987200000,
  "updated": 1476031548000,
  "utc_offset": -14400000,
  "waitlist_count": 0,
  "yes_rsvp_count": 4,
  "group": {
  "created": 1386453720000,
    "name": "Pinellas Hack Shack",
    "id": 11376752,
    "join_mode": "open",
    "lat": 27.84000015258789,
    "lon": -82.72000122070312,
    "urlname": "Pinellas-Hack-Shack",
    "who": "Twidgits",
    "category": {
      "id": 34,
      "name": "Tech",
      "shortname": "Tech",
      "sort_name": "Tech"
    }
  },
  "link": "https://www.meetup.com/Pinellas-Hack-Shack/events/240185831/",
  "description": "<p>This is the Sunday General Workshop.  Come in, work on anything you like!</p> ",
  "visibility": "public"
},

As you can see under group then category then id there is 34 . From what I read I don't think you can just get the categories you want. But you can map over this response and filter out the categories you are looking for.

And yes, you will have to filter the response on the client side. Something like this should work:

const arrayOfOnly34 = Object.keys(result).reduce((acc, curr) => {
  const value = result[curr]
  if (value.group.category.id === 34) {
    acc.push(value)
  }
  return acc
}, [])

The way I have achieved this is by using the version 2 get/2/open_events API method which allows you to specify categories (along with many other parameters).

The link to this method in the Meetup API console is:

https://secure.meetup.com/meetup_api/console/?path=/2/open_events

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM