Giter Club home page Giter Club logo

instagram's Introduction

Show a profile Instagram feed in TYPO3

Introduction

In the past we did a lot of research to bypass the original Instagram API. Using the official interface is still pain. Now version 6 of this extension respects that Instagram updated their website (some days ago) again and cover it against image grapping. So, we decided now to use the official API in this extension to still deliver images on our website. Nevertheless we want to make the configuration as easy as possible even if there is some hard stuff for non-developers now. Version 6 has some breaking changes because of the switch to the API now (see details below).

Explanation

This extension is splitted into two parts. A scheduler where you can import an instagram feed into the database on the one hand and on the other hand there is a plugin where you can show the feed on your page. The split gives us the possibility to still show images even if the interface is broken and in addition there are no speed limitations with this kind of architecture. Because of the guidelines of Instagram/Facebook the first step to use the API must be done by yourself and by hand. You have to add a facebook developer account and add a new "app". After that you have to get the token by yourself in a browser. Once you have did this, the token can be refreshed automatically. So you do not have to make the whole initialization again. See details below.

Installation

composer require in2code/instagram

Configuration

The facebook and instagram part

First of all, you should follow the official guidelines with step 1, 2 and 3 - see details at https://developers.facebook.com/docs/instagram-basic-display-api/getting-started

  • Step 1: You need a facebook developer user - see https://developers.facebook.com/apps
  • Step 2: Add a "facebook app" as described in the guidelines in step 1
  • Step 3: Configure "Instagram Basic Display" in the guidelines in step 2 ** Note: Simply use the homepage URL of your website for the "OAuth Redirect URIs" like https://www.in2code.de/ (same for "Deauthorize Callback URL" and "Data Deletion Request Callback URL") ** Note2: Make some notes for your new "App ID", "App secret" and the "Redirect URI" - this will be needed later in the FlexForm
  • Step 4: Add a instagram testuser as described in step 3 in the guidelines
  • Step 5: Install the extension (if not yet done)
  • Step 6: Add a Instagram plugin anywhere on your pages and open the edit view. Add "username", "App ID", "App secret" and "App return URL" and press "save"
  • Step 7: Now you will see a button at the end of the FlexForm. Click on it and a new browserwindow is opened with the Instagram website. You have to login and accept the request. After that, you will be redirected to your homepage.
  • Step 8: If you now reload the plugin, you will see a green message that tells you that you now have a valid token and how long the token is valid (no worry, ones you have created it, you can use a scheduler task to refresh it automatically)
  • Step 9: Now, you have access to the API and you can add a new scheduler task and import images from the given user (You should frequently import the feed - e.g. every 30 minutes)
  • Step 10: Once you have imported the images via scheduler, you can see the plugin output in the frontend with the given feed
  • Step 11: Don't forget to add an additional scheduler task to frequently refresh the token validation after 30-50 days, because the long-live token in Instagram expires after 60 days.

CLI commands

Import images

If you have access to the instagram API (look at the FlexForm in the plugin and watch for the green message), you can import images via CLI or scheduler.

Import the latest 25 posts from in2code.de:

./vendor/bin/typo3 instagram:importfeed in2code.de

Import some posts and get notified if error happens via Email:

./vendor/bin/typo3 instagram:importfeed in2code.de [email protected]:

Refresh tokens

Because long-live-tokens are only valid for 60 days, you can automatically refresh them after some days - with:

./vendor/bin/typo3 instagram:refreshtoken in2code.de

Remove all tokens

If you change your instagram password, all generated tokens are not useable any more. You have to add new ones. But first of all, you can delete them:

./vendor/bin/typo3 instagram:removetokens

Scheduler

Import images

Add a new scheduler task of type Execute console commands (scheduler) and select instagram:importfeed. Now you can add a frequency (e.g. */30 * * * * for every 30 minutes), a instagram username and one (or more) email address if error happens (and you want get notified).

Scheduler task

Field Description
username Every task can import current posts from one user. If you want to show more feeds, you have to add more tasks.
receivers Optional: Get notified via email if a CURL error occurs (e.g. if instagram blocks your requests). Commaseparated email list is provided.

Refresh tokens

There is a new scheduler task, that can be used to automatically refresh Instagram tokens. We would do this after 30-50 days because a long-live token is valid for only 60 days.

Add a new scheduler task of type Execute console commands (scheduler) and select instagram:refreshtoken. Now you can add a frequency (e.g. 0 5 */30 * for every 30 days at 5 am) and a instagram username.

HTML output modification

Overwrite and modify the HTML output:

plugin {
    tx_instagram_pi1 {
        view {
            templateRootPaths {
                0 = EXT:instagram/Resources/Private/Templates/
            }
        }
    }
}

Example html:

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
	  xmlns:instagram="http://typo3.org/ns/In2code/Instagram/ViewHelpers"
	  data-namespace-typo3-fluid="true">

<div class="c-socialwall">
	<div class="c-socialwall">
		<f:for each="{feed.data}" as="image" iteration="iteration">
			<f:if condition="{iteration.cycle} <= {settings.limit}">
				<div class="c-socialwall__item c-socialwall__item--instagram">
					<f:link.external uri="{image.permalink}" title="Instagram profile {settings.username}" target="_blank" rel="noopener">

						<instagram:isLocalImageExisting id="{image.id}">
							<f:then>
								<picture>
									<source srcset="{f:uri.image(src:'/typo3temp/assets/tx_instagram/{image.id}.jpg', width:'500c', height:'500c', fileExtension: 'webp')}" type="image/webp">
									<source srcset="{f:uri.image(src:'/typo3temp/assets/tx_instagram/{image.id}.jpg', width:'500c', height:'500c', fileExtension: 'jpg')}" type="image/jpeg">

									<img
										src="{f:uri.image(src:'/typo3temp/assets/tx_instagram/{image.id}.jpg', width:'500c', height:'500c')}"
										title="{image.caption -> f:format.crop(maxCharacters: 120, append: ' ...')}"
										alt="{image.caption -> f:format.crop(maxCharacters: 120, append: ' ...')}"
										loading="lazy" />
								</picture>
							</f:then>
							<f:else>
								<f:comment>
									If image is not available on the local machine (for any reasons), load from instagram directly
								</f:comment>
								<img
									src="{image.media_url}"
									title="{image.caption -> f:format.crop(maxCharacters: 120, append: ' ...')}"
									alt="{image.caption -> f:format.crop(maxCharacters: 120, append: ' ...')}"
									width="500"
									height="500" />
							</f:else>
						</instagram:isLocalImageExisting>

						<p>{image.caption}</p>
					</f:link.external>
				</div>
			</f:if>
		</f:for>
	</div>
</div>

</html>

Styling

If you want to have basic styling for the default layout present in the extension, you can include the static template "Instagram" on your page.

Screenshots

Example frontend output:

Images from the instagram feed

Plugin in backend:

Plugin Flexform

Plugin overview in backend page module:

Plugin preview

Technical corner

How to use the facebook/instagram API in general and how to test it? See documentation: ApiDocumentation

FAQ

Q: The configuration in Instagram sounds complicated

A: Yes, we did a lot in the past to give you a gdpr proved and quick to install solution to show your instagram images on your website. Now Instagram updated their websites again, to block "easy" image grabbing. At the moment we do not see a simpler way then described above and also respect privacy for your visitors.

Q: I clicked the button in the FlexForm and accepted but after that an error is shown

A: Instagram redirect you back to the configured url. If this is (e.g.) your startpage a PSR-15 middleware is listening for GET params like &code=foo. This param is given from Instagram (not from us).

Q: There is no (e.g. german) translation of the plugin

A: Yes, at the moment we focussed on english to speed up developing.

Q: Token is only valid for 60 days. Do I have to refresh it manually?

A: No, if there is a valid token, you can refresh it (e.g.) after 30 days automatically via another scheduler task.

Q: Error "OAuthException: Insufficient developer role Code: 400" comes up after clicking the button?

A: Take care that you are logged in into facebook with your developer account at the same time

Q: How to add a GDPR-known button in frontend for the visitors?

A: No worries, this extension is absolutely GDPR-friendly. Text and images are stored anonymized on the server. No button needed for this.

Q: Can I access to any instagram account?

A: No, because Instagram wants you to enable the access to the account, the owner has to accept this.

Q: Is an approvement needed when building a Facebook app?

A: No, an approvement from Facebook is not needed.

Q: Instagram password was changed - now I can't update the feed.

A: If you change the instagram password, all tokens are not valid any more. An error comes up like

{"error":{"message":"Error validating access token: The session has been invalidated because the user changed their pass (truncated...)

In this case you have to remove all tokens (see CLI section above) and create new ones from the scratch.

Changelog

Version Date State Description
8.0.0 2023-10-24 Task Support TYPO3 11 and 12 now
7.2.0 2023-02-16 Task Add PHP 8 support
7.1.0 2022-09-22 Feature Add optional static file include for styling of default layout
7.0.0 2022-02-21 Task Support TYPO3 10 and 11 now
6.2.1 2021-10-01 Bugfix Prevent exception if image is a video
6.2.0 2021-07-09 Feature Add comand that allows you to delete all existing tokens
6.1.3 2021-06-09 Bugfix Use thumbnail images when storing local to allow video previews
6.1.2 2021-06-09 Bugfix Don't convert UserId to float value
6.1.1 2021-06-09 Task Harden middleware with code recognization
6.1.0 2021-04-13 Task Fix problem "Field id specified more than once. This is only possible before version 2.1" - because of a change of the instagram interface
6.0.2 2021-03-17 Task Add extension key to composer.json file, small documentation update
6.0.1 2021-03-15 Bugfix Change int to string field type for userId and appId to also handle large numbers
6.0.0 !!! 2021-03-15 Task Another rebuild now with the useage of the original Instagram API to grap images. See installation part in documentation what you have to do now. FlexForm, Scheduler and HTML-Templates have changed (this is a pitty, but have to be done).
5.1.0 2021-01-21 Feature Render images in listview in webp format.
5.0.2 2020-12-23 Bugfix Add a subject for error mails.
5.0.1 2020-11-27 Bugfix Enable caching for the plugin.
5.0.0 2020-11-16 Feature Pass a sessionid to instagram for blocked requests. Added a notification service for CURL errors.
4.0.1 2020-11-14 Bugfix Fix typo in ext_tables.sql
4.0.0 !!! 2020-11-13 Task Add a scheduler task to import feeds (without RSS feed now). A plugin allows you to push the images into the frontend
3.0.0 !!! 2020-06-05 Task Use RSS-feed now for a workarround that server request are blocked by instagram
2.0.0 2020-05-08 Task Store images locally now to improve privacy of your visitors. Use content element uid for building individual caches now
1.1.0 2020-04-29 Task Open links in new tabs, don't cache the view because of own caching framework usage
1.0.0 2020-04-29 Task Initial release

instagram's People

Contributors

apm-thomas-hempel avatar beardcoder avatar cehret avatar einpraegsam avatar ichhabrecht avatar juergen-venne avatar mschwemer avatar pixeldesu avatar quidage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

instagram's Issues

Receiving account information

Dear Alex,
I am interested in using this ext on a future website. But I have a question. Maybe it is possible already but I could not find anything about it: It would be great to get account information of the insta account e.g. number of posts, number of followers, profile image or "Steckbrief".
Thanks for your work
Martin

Can I only access IG Posts from Accounts I own?

Maybe I understand the extension wrong, but I thought that I could post from every (public ) account.
After a successfull test with my private account I changed it to an another username, initiated the post fetch but in the DB were only the posts of my account (under the IG username of the another account).

Import Error: "Unsupported request - method type: get"

A few days ago, the import task on our website started to fail on execution with the following error:

{ "error": { "message": "Unsupported request - method type: get", "type": "IGApiException", "code": 100, "fbtrace_id": "AI9LIdMR9ygI6-M7wbjRuEM" } }

The requested uri looks like this: https://graph.instagram.com/{user_id}/media/?fields=media,caption,media_type,media_url,permalink,thumbnail_url,timestamp,username,children&access_token={access_token}

When I remove "media_url" from the uri, the feed ist shown (without media_url).

When I try to access the media item itself like this, the media_url is displayed: https://graph.instagram.com/{media_id}/?fields=caption,media_type,media_url,permalink,thumbnail_url,timestamp,username,children&access_token={access_token}

Local storing of images

Hello,
set up the extension, everything works great!
Just one question: How can I store/cache the preview images locally?
They always seem to link back to instagram.

Thanks

editing the Instagram Page with html

I've been having trouble to find a way to edit the imported instagram posts with HTML in order to style the Instagram feed accordingly.

How would I go about this? I would really love the feed to look like the example that you provided.

kind regards

[Question] FB-App approvement

The create Facebook App is at the beginning in a "development" mode. Do I have to submit the App to approvement and make it Live or can it run in the Development mode?

Undefined variable in PrepareFeed.php

Since today it is so that after the scheduler task has started, an error message comes and I receive an e-mail with the following error message:
Message: PHP Warning: Undefined array key "thumbnail_url" in /home/webserver/typo3v11.martini-klinik.de/www/docs/typo3conf/ext/instagram/Classes/Domain/Service/PrepareFeed.php line 69 (1476107295)

Latest version and we haven't changed anything for weeks. It ran completely problem free so far.

UserId ist converted to float

When creating a Token the user_id is converted to float.

/Classes/Domain/Repository/InstagramRepository.php -> getShortLiveTokenResult

[FEATURE] Allow to Update Token in Plugin Form

We had a situation lately that the client changed the Password of his IG Account. In this case the Token is no longer valid.
To Fix this I had to run the "delete token" Cron Task and then the Client could press the button again to get a fresh token.
The problem is that the Tasks can only be called by Admin users in TYPO3, which the client accounts not always have (and want).
Could it be possible that event when the Plugin have a valid token, the Button to get a new token is always visible? Or a Button to delete the token vie a Button click in the Plugin.

PHP-error when importing posts of type CAROUSEL_ALBUM

We encountered the following error:

503
Oops, an error occurred!
In2code\Instagram\Domain\Service\PrepareFeed::getImageContent(): Argument #1 ($url) must be of type string, null given, called in /var/www/htdocs/public/typo3conf/ext/instagram/Classes/Domain/Service/PrepareFeed.php on line 69
TypeError thrown in file /var/www/htdocs/public/typo3conf/ext/instagram/Classes/Domain/Service/PrepareFeed.php in line 82.

In our case the error was caused by a post of type CAROUSEL_ALBUM.

edit: added line 'TypeError thrown ...'

TYPO3 10.4.13 Scheduler Error

Die Ausführung von Task "Konsolenbefehle ausführen (scheduler)" ist fehlgeschlagen mit folgender Meldung: Task failed to execute successfully. Class: TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask, UID: 8

Scheduler ausgeführt manuell und via crontab.
Andere Crons via "Konsolenbefehle ausführen (scheduler)" funktionieren bzw. werden ausgeführt.

TYPO3 10.4.13
Instagram 5.1.0
PHP 7.4

Incompatible with oauth2 extension

When using the ext-oauth2-client extension, the login process throws an In2code\Instagram\Exception\ConfigurationException.

This is due to the identical query parameter code in the returnUrl which the GetAuthenticationCode middleware falsely interprets the request as an authentication redirect of instagram.

Since the oauth redirect contains more parameter than just code, I would add an additional check for the amount of parameters in the isInstagramAuthentificationRedirect.

PR will follow.

PHP-error display Feed

Hi,
Feed is integrated and is also displayed correctly in the backend.
But in the frontend I get the following error:

PHP Warning: Attempt to read property "data" on null in /var/www/vhosts/website/typo3conf/ext/instagram/Classes/Controller/ProfileController.php line 41

PHP 8.3
Typo3 11.5.36

Wrong syntax of crontab frequeny example

In the documentation of "Refresh tokens" an asterisk is missing in the example.
"(e.g. 0 5 */30 * for every 30 days at 5 am)" should be "(e.g. 0 5 */30 * * for every 30 days at 5 am)".

Task failed to execute successfully.

Hi,
I get the same error like #2 when I try to import the feeds.

Die Ausführung von Task "Konsolenbefehle ausführen (scheduler)" ist fehlgeschlagen mit folgender Meldung: Task failed to execute successfully. Class: TYPO3\CMS\Scheduler\Task\ExecuteSchedulableCommandTask, UID: 5

I can't check the import via CLI commands.

I'm using 6.2.1 on TYPO3 10.4.21.

Any idea what could go wrong?

Thanks

The dimension of the picture are ignored

Hey, the dimension of the pictures are ignored:

<img
									src="{f:uri.image(src:'/typo3temp/assets/tx_instagram/{image.id}.jpg', width:'200c', height:'200c')}"
									title="{image.caption -> f:format.crop(maxCharacters: 120, append: ' ...')}"
									alt="{image.caption -> f:format.crop(maxCharacters: 120, append: ' ...')}"
									loading="lazy" />

All the pictures has the maximum dimension ca. 900px, no cropping.....

TYPO3 : 10, latest instagram

GDPR opt-in button

Hi, Super extension, I could make it run, but is these a way to make it GDPR-conform, like an opt-in button?

Default limit of 25 images

By default instagram has a limit of 25 images when you use the API.
You can set the limit in the plugin for the frontend output up to 100, but there are never more than 25 images to display. Because the import is limited by default to 25.

In the instagramRepository.php, you can set f.e. a limit which is defined by TypoScript Constant or Extension Settings.

        $url = 'https://graph.instagram.com/' . $tokenRecord['user_id'] . '/media/'
            . '?fields=media,caption,media_type,media_url,permalink,thumbnail_url,timestamp,username,'
            . 'children&access_token=' . $tokenRecord['token'] . '&limit=100';

With the limit parameter you can import more then 25. Up to 100.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.