iliain/silverstripe-insta

Provides Instagram login code and feed collector for Silverstripe

Installs: 22

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

2.0.1 2023-04-18 01:08 UTC

This package is auto-updated.

Last update: 2024-03-18 03:21:31 UTC


README

Code for Silverstripe that interacts with the Express auth app. This is designed to query the app found here and will not function without it. The code is designed to provide a login link, store incoming tokens, and use said tokens to request feed information from the Basic Display API, nothing more.

Installation (with composer)

composer require iliain/silverstripe-insta

Config

You'll need to define the following variables in your config:

Instagram:
  auth_handler_url: 'https://locationofauthhandler.app'
  cache_file: 'filename.txt'

auth_handler_url is used to define the URL where the auth app is located, while cache_file simply determines the name assigned to the local cache file for the feed.

Usage

Once configured, the code will add a new section to the site Settings in the CMS. Users can use this to log in and authorise an account, which will then store an access token. From here, you can then use the InstagramCacheTask to query the Basic Display API for you and retrieve some posts, which will then be stored in a local file in the public directory. A limit can be included, but is optional.

Frontend: mysite.com/dev/tasks/set-instagram-cache?limit=5
Backend:  sake dev/tasks/set-instagram-cache "limit=5"

You can use code like the following example to pull this data into the frontend:

public function getInstagramFeed()
{
	$path = Config::inst()->get('Instagram', 'cache_file');
	$cache = file_get_contents($path);
	return unserialize($cache);
}

The fields available to display are the following:

  • ID
  • Username
  • Caption (stored as a Text DBField)
  • Link
  • Image (returns thumbnail_url if present, defaults to media_url if not)
  • Timestamp (stored as a Datetime DBField)