Kirby CMS User-Field, Tag and Page Method to access Instagram API Endpoints. This is a boilerplate to create your own Instagram embeds.
Use this plugin to simplify the secured api authorisation to a few clicks and show your Instagram images and metadata without any fixed styling embed codes.
This is not an Embed Code Plugin but grants you access to all API Endpoints. It works without implicit OAuth and can use Signed Requests.
You will have to parse the result of the endpoint to generate your html-elements using snippets
– see example.
Be aware that using the Instagram API has rate limits.
NOTE: This is not a free plugin. In order to use it on a production server, you need to buy a license. For details on Kirby InstagramAPI's license model, scroll down to the License section of this document.
- access Instagram API Endpoints
- use
snippets
to customize the output - simply extend existing Kirby CMS User-Accounts with Kirby User Roles
- or use existing token
- responses can be cached
- includes helper to cache images
Once installed, configured and authorized you can output your images like this:
use the Kirby-Tag
(instagramapi: mykirbyusername_or_token endpoint: users/self/media/recent snippet: ia-example-media)
or plain php
// snippet
snippet('ia-example-media', ['user'=>'mykirbyusername_or_token', 'endpoint'=>'users/self/media/recent']);
// page or site methods
$result = $page->instagramapi('mykirbyusername_or_token', 'users/self/media/recent');
foreach($result['data'] as $data) { /*...*/ }
kirby plugin:install bnomei/kirby-instagram-api
$ git submodule add https://github.com/bnomei/kirby-instagram-api.git site/plugins/kirby-instagram-api
- Download the contents of this repository as ZIP-file.
- Rename the extracted folder to
kirby-instagram-api
and copy it into thesite/plugins/
directory in your Kirby project.
Create a new Client and get Instagram Client ID and Secret and set them in your /site/config/config.php
.
c::set('plugin.instagram-api.client-id', 'YOUR_CLIENT_ID_HERE');
c::set('plugin.instagram-api.client-secret', 'YOUR_CLIENT_SECRET_HERE');
Setup Client Security with Valid redirect URIs, Disabling Implicit OAuth and Enforced Signed Requests at the Instagram Developer Site. Now you have an Instagram App.
Make sure to attach kirby-instagram-api/redirect to your redirect URI or it will not work. Also verify protocol.
HTTP?
http://YOUR_REDIRECT_URI_HERE/kirby-instagram-api/redirect
Or HTTPS?
https://YOUR_REDIRECT_URI_HERE/kirby-instagram-api/redirect
If you are using https
consider setting the option to enforce this in the Panel as well as in Kirby.
Unless you intend to go live with your Instagram App right away you need to add up to 10 users to the Sandbox. You can do that at the Instagram Developer Site.
Add the instagramapi
field by extending a role blueprint to existing user accounts.
# site/blueprints/users/admin.yml
fields:
instagramapi: instagramapi
- Before triggering any emails make sure you sending email is correct by setting either
plugin.instagram-api.email.from
oremail.from
. Sending emails might not work onlocalhost
since Kirby's email() helper is used. - Then send the email with the Authorization Link using the Button at the Users Panel View.
- Open the email and authorize. The data will be stored at the user account and the user will get a second verification email containing a backup of that data.
You can define your own subject and body-snippet for both emails using settings and snippets
– see settings below.
(instagramapi: mykirbyusername_or_token endpoint: users/self/media/recent snippet: ia-example-media)
If you use the same snippet or endpoint everytime consider setting a default in your site/config/config.php
.
c::set('plugin.instagram-api.tag.endpoint', 'users/self/media/recent');
c::set('plugin.instagram-api.tag.snippet', 'ia-example-media');
This simplifies the Kirby-Tag call to:
(instagramapi: mykirbyusername_or_token)
See snippet
ia-example-media.
snippet('ia-example-media');
// or if you want to override the defaults
snippet('ia-example-media', ['user'=>'mykirbyusername_or_token', 'endpoint'=>'users/self/media/recent']);
Of course you can use the Page or Site Methods directly. Take a look at the example how to setup user, endpoint and parse the result.
If you already have a token
you can use this plugin without its Kirby User Field. Like it was suggested by @olach in Issue #1. Just use your token
instead of the username.
(instagramapi: TOKEN endpoint: users/self/media/recent snippet: ia-example-media)
$result = $page->instagramapi('TOKEN', 'users/self/media/recent');
foreach($result['data'] as $data) { /*...*/ }
If you set the token in you site/config/config.php
. It will be used unless you provide a username or other token.
c::set('plugin.instagram-api.default-token', 'TOKEN');
(instagramapi: endpoint: users/self/media/recent snippet: ia-example-media)
// suggested
$result = $page->instagramapi(c::get('plugin.instagram-api.default-token'), 'users/self/media/recent');
// but this will also work
$result = $page->instagramapi(null, 'users/self/media/recent');
foreach($result['data'] as $data) { /*...*/ }
You can set these in your site/config/config.php
.
- default: ''
- add your license here and the widget reminding you to buy one will disappear from the Panel.
- default:
0
- time in seconds to cache json responses to
/site/cache/
.
- get it from Instagram Deverloper
- get it from Instagram Deverloper
- default:
basic
- set this if you want to request a different permission scope. Might need an approved instgram app not just a sandbox app.
c::set('plugin.instagram-api.scope', 'public_content+likes');
- default: ''
- set this if you want to ommit specifying the token.
- default: ''
- set this if you want to ommit specifying the endpoint in the tag.
c::set('plugin.instagram-api.tag.endpoint', 'users/self/media/recent');
- default: ''
- set this if you want to ommit specifying the snippet in the tag.
c::set('plugin.instagram-api.tag.snippet', 'ia-example-media');
- default: email.from or it might fail
- default: email.subject or 'Kirby CMS InstagramAPI Plugin: Authorization Email'
- default: instagramapi-email-request-body
- default: email.subject or 'Kirby CMS InstagramAPI Plugin: Authorization Email'
- default: instagramapi-email-success-body
- default: email.service or
instagramapi-html
- use the html email service provided by this plugin or set your own email service
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
I am in no way affiliated with the google map places referenced in this readme and the examples. I just liked their names.
Kirby InstagramAPI can be evaluated as long as you want on how many private servers you want. To deploy Kirby InstagramAPI on any public server, you need to buy a license. You need one unique license per public server (just like Kirby does). See license.md
for terms and conditions.
However, even with a valid license code, it is discouraged to use it in any project, that promotes racism, sexism, homophobia, animal abuse or any other form of hate-speech.
Technical support is provided on GitHub only. No representations or guarantees are made regarding the response time in which support questions are answered. But you can also join the discussions in the Kirby Forum.
Kirby InstagramAPI is developed and maintained by Bruno Meilick, a game designer & web developer from Germany. I want to thank Fabian Michael for inspiring me a great deal and Julian Kraan for telling me about Kirby in the first place.