Stars: 133
Forks: 54
Pull Requests: 4
Issues: 26
Watchers: 23
Last Updated: 2020-03-14 23:44:09
inWidget - free Instagram widget for your website. Allows you to show photos from an Instagram account, by hashtags and more.
License: Other
Languages: PHP, CSS
This library is based on PHP and allows you to show photos from an Instagram account on your website.
PHP >= 5.4.0 with cURL extension
Download source code. Extract /inwidget folder. Upload /inwidget folder to website with all files inside.
Or use composer
composer.phar require aik27/inwidget
composer require aik27/inwidget
Note. inWidget using relative paths, so you can upload it to any folder. After that do not forget change URL in IFRAME tag.
inWidget will store cached data in /inwidget/cache folder. If this directory does not have write permissions you will see ERROR #101.
Modify /inwidget/config.php You will need to specify Instagram login and other params
List of parameters:
<!-- default -->
<iframe src='/inwidget/index.php' scrolling='no' frameborder='no' style='border:none;width:260px;height:330px;overflow:hidden;'></iframe>
Or use another examples with different display type:
<!-- Without profile -->
<iframe src='/inwidget/index.php?toolbar=false' data-inwidget scrolling='no' frameborder='no' style='border:none;width:260px;height:320px;overflow:hidden;'></iframe>
<!-- Mini 1 -->
<iframe src='/inwidget/index.php?width=100&inline=2&view=12&toolbar=false' data-inwidget scrolling='no' frameborder='no' style='border:none;width:100px;height:320px;overflow:hidden;'></iframe>
<!-- Mini 2 -->
<iframe src='/inwidget/index.php?width=100&inline=1&view=3&toolbar=false' data-inwidget scrolling='no' frameborder='no' style='border:none;width:100px;height:320px;overflow:hidden;'></iframe>
<!-- Horizontal orientation -->
<iframe src='/inwidget/index.php?width=800&inline=7&view=14&toolbar=false' data-inwidget scrolling='no' frameborder='no' style='border:none;width:800px;height:295px;overflow:hidden;'></iframe>
<!-- Large previews -->
<iframe src='/inwidget/index.php?width=800&inline=3&view=9&toolbar=false&preview=large' data-inwidget scrolling='no' frameborder='no' style='border:none;width:800px;height:850px;overflow:hidden;'></iframe>
Parameters are passed as GET variables when accessing to the widget script. For that you must change the URL in IFRAME tag. For example, to set the widget width to 600px and display five photos per a single row, you need to add appropriate parameters in the URL.
/inwidget/index.php?width=600&inline=5
List of parameters:
When you changing width or number of photos, do not forget to change IFRAME tag size.
Add GET variable "adaptive" in the URL of IFRAME tag.
/inwidget/index.php?adaptive=true
The value must be set to true. After that, the widget will automatically adjust to the dimensions of html container or browser window. In this case, the GET parameter "width" will be ignored, the "inline" parameter will have an effect when the widget width of more than 400px.
Please, see demonstration of adaptive mode: https://inwidget.ru/adaptive.php
https://www.youtube.com/watch?v=_O669Dx3djw
The URL to generate ACCESS TOKEN:
https://www.instagram.com/oauth/authorize/?client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&response_type=token&scope=basic
The widget can work with two kinds of API (undocumented and endpoints). Default API is undocumented. Access token is not required for it. Specifying ACCESS TOKEN in the widget's settings takes it to Endpoints API mode (https://www.instagram.com/developer/). If you want to create your own application in Instagram, then use video instruction above. Keep in mind that your application will first get into "sandbox" with following limits:
Keep in mind that Instagram has announced the end of support for endpoint API by 2020. More information: https://developers.facebook.com/blog/post/2018/01/30/instagram-graph-api-updates/
You can include inWidget library in your application and set parameters through the class constructor. Be careful with the file paths when using example below. The classes support autoloading.
By default the widget use undocumented API that provided by instagram-php-scraper library. To switch to the endpoint API, you need to specify ACCESS_TOKEN.
#require_once 'inwidget/classes/Autoload.php';
require_once 'inwidget/classes/InstagramScraper.php';
require_once 'inwidget/classes/Unirest.php';
require_once 'inwidget/classes/InWidget.php';
try {
// Options may change through the class constructor. For example:
$config = array(
'LOGIN' => 'fotokto_ru',
'HASHTAG' => '',
'ACCESS_TOKEN' => '',
'authLogin' => '',
'authPassword' => '',
'tagsBannedLogins' => '',
'tagsFromAccountOnly' => false,
'imgRandom' => true,
'imgCount' => 30,
'cacheExpiration' => 6,
'cacheSkip' => false,
'cachePath' => $_SERVER['DOCUMENT_ROOT'].'/inwidget/cache/',
'skinDefault' => 'default',
'skinPath'=> '/inwidget/skins/',
'langDefault' => 'ru',
'langAuto' => false,
'langPath' => $_SERVER['DOCUMENT_ROOT'].'/inwidget/langs/',
);
$inWidget = new \InWidget\Core($config);
// Also, you may change default values of properties
/*
$inWidget->width = 800; // widget width in pixels
$inWidget->inline = 6; // number of images in single line
$inWidget->view = 18; // number of images in widget
$inWidget->toolbar = false; // show profile avatar, statistic and action button
$inWidget->preview = 'large'; // quality of images: small, large, fullsize
$inWidget->adaptive = false; // enable adaptive mode
$inWidget->skipGET = true; // skip GET variables to avoid name conflicts
$inWidget->setOptions(); // apply new values
*/
$inWidget->getData();
include 'inwidget/template.php';
}
catch (\Exception $e) {
echo $e->getMessage();
}
ERROR #101 - can not access to the cached file. You need to change permissions for directory: /inwidget/cache
If cached file does not exist, the widget will try to create it. Then the widget will try to open it for reading and writing. Incorrect rights provide this error. If you already had some files in the cache directory, just delete them, because they also may has incorrect rights.
ERROR #102 - can not get the last modification time of the cached file.
Perhaps, this function is limited or not supported by your server's file system. If the widget can not determine the time, cache will always be irrelevant, which will result in permanent requests to Instagram API.
ERROR #500 - unknown error
Please, see what exactly was written into the cached file. This error is generated by the official API or instagram-php-scraper library. In most cases, it means a problem when sending or receiving data from Instagram server. Delete the cached file and refresh a page (on which the widget is displayed) to try send request again.
inWidget is a non-profit library that exists on bare enthusiasm. Your support are welcome!
PayPal: [email protected]
Thank you!
This library is free software; you can redistribute it and/or modify it under the terms of MIT license: https://inwidget.ru/MIT-license.txt