Making WordPress.org


Ignore:
Timestamp:
06/13/2018 07:38:35 PM (8 years ago)
Author:
coreymckrill
Message:

Official WordPress Events: Changes to Meetup API interface

The Meetup API is sporadically throwing back a 400 error on seemingly valid
requests. The changes here attempt to avoid these errors by using some of the
same strategies as WordCamp's Meetup API Client:

  • Re-sign every URL during a multi-page request
  • Chunk the group IDs into smaller batches
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/official-wordpress-events/official-wordpress-events.php

    r7292 r7304  
    322322                }
    323323
    324                 $groups = array_chunk( $groups, 200, true );
     324                // Meetup API sometimes throws an error with chunk size larger than 50.
     325                $groups = array_chunk( $groups, 50, true );
    325326
    326327                foreach ( $groups as $group_batch ) {
    327                         $request_url = sprintf(
    328                                 '%s2/events?group_id=%s&time=0,3m&page=%d&key=%s&status=upcoming,cancelled',
    329                                 self::MEETUP_API_BASE_URL,
    330                                 implode( ',', $group_batch ),
    331                                 200,
    332                                 MEETUP_API_KEY
     328                        $request_url = add_query_arg(
     329                                array(
     330                                        'group_id' => implode( ',', $group_batch ),
     331                                        'time'     => '0,3m',
     332                                        'page'     => 200,
     333                                        'status'   => 'upcoming,cancelled',
     334                                ),
     335                                self::MEETUP_API_BASE_URL . '2/events'
    333336                        );
    334337
    335338                        while ( ! empty( $request_url ) ) {
     339                                // The "next" URLs returned by the API need to be re-signed.
     340                                $request_url = add_query_arg(
     341                                        array(
     342                                                'sign' => true,
     343                                                'key'  => MEETUP_API_KEY,
     344                                        ),
     345                                        $request_url
     346                                );
     347
    336348                                $this->log( 'fetching more events from: ' . var_export( $request_url, true ) );
    337349
Note: See TracChangeset for help on using the changeset viewer.