Experiment with FourSquare, WordPress and the Keyring Social Importers plugin

Xavier Roy on Twitter by Xavier Roy (Twitter)

“@khurtwilliams Have you tried Keyring Social Importers? It does a pretty good job of importing from Instagram.”

Foursquare import to WordPress with modified Keyring Social Importers code. Thansk to @xavierroy for the suggestion. #IndieWeb #PESOS #Foursquare #WordPress

Xavier Roy on Twitter by Xavier Roy (Twitter)

“@khurtwilliams Have you tried Keyring Social Importers? It does a pretty good job of importing from Instagram.”

Update: Developer, Bewu Lebens has written a WordPress: Keyring Developer’s Guide. I will revisit how I used this plugin after I familiarise myself with the guide. I also plan on developing a Keyring importer for Untappd.

On Twitter, Xavier Roy posted a response to my post about my experiment with importing Instagram post to WordPress. He suggested I try the Keyring Social Importers plugin. After some back and forth on Twitter, I gave it a go and updated the original post.

The results were not pleasing. However, I was fascinated by the plugin and tried it with Foursquare.

The Keyring Social Importers plugin provides a set of social importers that pull in content created on other sites and re-publishes it on a WordPress site. After an initial import, the importers optionally check each hour and automatically download new content. New posts are created for each item imported with support for specific Post Formats, depending on the content type.

At the time of writing this, the plugin had not been tested on WordPress 4.9. The untested code can be unstable code and unstable code can lead to security leaks etc. so I configured and tested everything on a test instance of WordPress.

I also installed Keyring, a plugin which is required to use with Keyring Social Importer, and which provides the authentication and API connections to each of the external services. I configured API access to Foursquare and then from the “Tools->Import” section of the dashboard I clicked the link to authenticate and to start importing from Foursquare.

I’ve had my Foursquare account for a very long time so the import took a lot of time. Each check and photo on my Foursquare account was downloaded and imported into my WordPress Media Library. The imported image was attached to each post as a featured image, which is a feature I wanted, however, each image was also attached in the body of every post and is only 640px × 479px.

The importer leverages the Post Kinds and Simple Location IndieWeb plugins to set the Post Kind to Photo and set the geographic location for the post. However, syndication links were not set. But it’s not too much work to set it manually later.

The Foursquare importer works but the results were not attractive. First, I did not want to import every one of my past check-ins. I wanted to limit the initial set of imports. Second, I wanted the higher resolution version of the image.

For example, for check-in at Osteria Procaccini, the Keyring Social Importer imports this image.

I poked around the web and learned that it’s possible to get at this image via the Foursquare API. I discovered that by modifying the image URL and replacing the image dimension with the text original, I could get at the full-size images. But I also discovered that I could get what I wanted by removing some HTML.

What I needed to do was to find the section of code that imports images, and change the code to import the higher-resolution image.

In the wp-content/plugins/keyring-social-importers/keyring-importers.php file, I found the following code between lines 865 to 876. If I removed that code, I would have everything I wanted.

if ( $data ) { $img = ‘<img class="keyring-img" src="' . esc_url( $data[0] ) . '" alt="' . esc_attr( $post['post_title'] ) . '" width="' . esc_attr( $data[1] ) . '" height="' . esc_attr( $data[2] ) . '" />’; } // Regex out the previous img tag, put this one in there instead, or prepend it to the top/bottom, depending on $append if ( stristr( $post['post_content'], $url ) ) { $post['post_content'] = preg_replace( '!<img />]*src=[\'"]' . preg_quote( $url ) . '[\'"][^>]*>!', $img, $post['post_content'] ) . "\n"; } else if ( $append ) { $post['post_content'] = $post['post_content'] . "\n\n" . $img; } else { $post['post_content'] = $img . "\n\n" . $post['post_content']; } }

The default is for Keyring Social Imports to import 200 posts in oldest to newest order. I didn’t want every post and I wanted only one newest post. A modification to line 74 of the wp-content/plugins/keyring-social-importers/importers/keyring-importer-foursquare.php file yielded the results I wanted.


$url = "https://api.foursquare.com/v2/users/" . $this-&gt;get_option( 'user_id', 'self' ) . "/checkins?limit=200";


$url = "https://api.foursquare.com/v2/users/" . $this-&gt;get_option( 'user_id', 'self' ) . "/checkins?limit=2&amp;sort=newestfirst";

I tested the code over the last few weeks and so far I have not encountered any issues. I think with these modifications to the code, the Keyring Social Importers plugin is a reliable PESOS WordPress plugin for importing Foursquare check-ins.

Montgomery Township, New Jersey, United States of America

Author: Khürt Williams

a human, an application security architect, avid photographer, nature lover, and formula 1 fan who drinks beer.

6 thoughts on “Experiment with FourSquare, WordPress and the Keyring Social Importers plugin”

  1. Hi Khürt, Beau here, the author of Keyring + the Social Importers.

    It's cool to see other folks trying out these plugins and having some success with them, and hearing feedback on what you'd change etc. I'd encourage you to post suggestions/feature requests etc in the GitHub repos for each project at https://github.com/beaulebens/keyring/issues (if it's related to service support, or basic auth type things), or https://github.com/beaulebens/keyring-social-importers/issues (if it's about one of the importers).

    Are you by any chance using a really old version of the plugins or something? The plugin does specifically try to get the fullsize image for Foursquare/Swarm check-ins currently, as seen here: https://github.com/beaulebens/keyring-social-importers/blob/master/importers/keyring-importer-foursquare.php#L186

    There's also a constant available (self::NUM_PER_LOAD) if you'd like to easily control the number of items downloaded per request. You might also be interested in the keyring_importer_stop_after_imported_count filter, which was added to help with debugging and add some control over what gets imported: https://github.com/beaulebens/keyring-social-importers/pull/11/files#diff-f80b92367102fa02a38bf7d6911e08d5


    1. Hi Beau,

      I was using an older version of the plugin when I wrote that article. The newer version does indeed use the full-size image for Foursquare/Swarm check-ins. It works very well. I did not know about the constant. Thanks for that tip about self::NUM_PER_LOAD and keyring_importer_stop_after_imported_count.

  2. I would love to be able to import my Instagram comments to my WordPress posts and I saw another of your posts about doing it with Twitter. Unfortunately, Instagram doesn’t let you do it like Twitter does

  3. Pingback: KHÜRT WILLIAMS

Comments are closed.