Experiment with FourSquare, WordPress and the Keyring Social Importers plugin

Replied to
 Aperture ƒ/11  Credit Khürt Williams  Camera NIKON D40  Captured 31 December, 2010  Focal length 35mm  ISO 200  Shutter speed 1/160s 

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.

Experiment with FourSquare, WordPress and the Keyring Social Importers plugin 108856 El7kZnp5nO4EESFJRB4KmxfXSfIcn mbceLEOylUfdM

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']; } }

Experiment with FourSquare, WordPress and the Keyring Social Importers plugin 108856 El7kZnp5nO4EESFJRB4KmxfXSfIcn mbceLEOylUfdM

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.

Before:

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

After:

$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.

Liked this post? Follow this blog to get more. 

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

  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. 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

    Cheers.

  3. 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

Mentions

  • KHÜRT WILLIAMS

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Learn More)