Montgomery Township, New Jersey

Experiment with FourSquare, WordPress and the Keyring Social Importers plugin

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

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.

Experiment with FourSquare, WordPress and the Keyring Social Importers plugin %name

Husband, father, Information security professional and avid photographer living at the junction of Princeton Township, Montgomery Township and Rocky Hill.

Montgomery Township, New Jersey, United States of America

Also on:

Liked this post? Follow this blog to get more. 

4 Comments on “Experiment with FourSquare, WordPress and the Keyring Social Importers plugin

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

%d bloggers like this: