Closed (fixed)
Project:
Media entity Instagram
Version:
8.x-1.2
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
28 Sep 2016 at 07:55 UTC
Updated:
3 May 2017 at 08:24 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
slashrsm commentedVideos should play I guess as we don't do anything custom with that. We just print the embed code.
With regards to the responsiveness I am not sure. Never really looked at it, but it would be very nice to support that. I assume this would only require a CSS tweak?
Comment #3
abaier commentedOkay, I tried it with another video and it worked. The before mentioned one does not even play on instagram.com itself, sorry …
Regarding the responsiveness I managed to solve this by leaving the pixel values (width/height) inside the display settings of the field formatter empty and assign the following css to the iframe:
width: 100%; max-width: 100%;… Its container element defines the final size, and everything now scales properly according to the browser width.To mention is, that this only worked after I added
//platform.instagram.com/en_US/embeds.jsto mylibraries.yml– without it the height of the iframe will not be recalculated to fit the actual size of the post and the content would be cropped.Instagram prepared this quite well, so we maybe don't really need the fixed size parameters, but rather percentage values:
(https://www.instagram.com/developer/embedding / Chapter: "Embedding for Developers")
Would be nice if you could have a look at this behaviour. Thanks in advance!
Comment #4
slashrsm commentedWould you upload the patch for that change that you did on your site?
Comment #5
abaier commentedI did not change anything in the module itself. I just left the fields inside the field formatter empty instead of adding pixel values. The rest was only css inside my theme.
Comment #6
slashrsm commentedSomething like this I guess....
Comment #7
slashrsm commentedComment #8
slashrsm commentedComment #9
abaier commentedSeems to work fine, thank you! The only thing I noticed was, that sometimes not all embedded posts got the right height assigned, when multiple posts were on one page.
Comment #10
slashrsm commentedComment #11
chr.fritschI got the same error like toni4i with multiple images. So i found this very small js https://github.com/ryanburnette/responsive-instagram, which worked very fine for me.
Here is a new patch
Comment #13
chr.fritschDamn it. Missed one test
Comment #14
abaier commentedHey @chr.fritsch, I reversed patch #6 and applied #13. Now I am experiencing, that the iframe of every individual post on the page gets the same fixed size, for me 610px width and 640px height, instead of applying the height of "iframe .embed", which would be the correct value. So I end up with some posts being cropped and some having whitespace below them.
Are there any other settings that I have to adjust or maybe some css that is necessary to make it work? I already set the iframe to width: 100%, max-width: 100%; to scale it within my container. But unfortunately the height does not get updated correctly.
Thanks for your help!
Comment #15
it-cruWhy you are using iFrame for a responsive embed of Instagram, when instagram API gives us a responsive oEmbed solution without requirement of API Key or Client ID for free?
https://www.instagram.com/developer/embedding/
Perhaps it would be better to re-factor the instagram embed field formatter to use oEmbed instead of iFrame?
Our old dirty way without using media_entity_instagram with an instagram paragraph:
Comment #16
chr.fritschI talked about that with slashrsm on IRC. We both think it makes sense to switch to the API approach. Would be nice if you could provide a patch for that
Comment #17
it-cruI will try to start working on a patch for this today. I think main problem is, that we does not request API when we render the instagram embed. Perhaps we could hold JSON response in some text field or so? Because when you have many instagram media entities in a node it blocks rendering.
Comment #18
it-cruPerhaps we can use https://www.drupal.org/project/json_field for storing JSON data from embed API call of each pinterest media entity. When we have only a source field we can fetch JSON directly as fallback?
Comment #19
it-cruI take a look at media_entity_twitter and I think it would be enoug to cache data from embedding JSON request. I will sprint on this before DrupalCamp in Munich next week if someone wants to join at Hubert Burda Media :)
Comment #20
it-cruNo caching of requested JSON from instagram embed API yet. Hide caption enable/disable per view mode. Hope I have time to work on JSON caching service on next days.
Comment #22
it-cruRe-factor patch from #20. Hope now tests does'n fail.
Comment #24
darrenwh commentedUpdated patch omitting test for iframe that has been removed and added interdiff.
Comment #25
darrenwh commentedComment #27
it-cruTomorrow I tink I've add a InstagramFetcher and caching like in media_entity_twitter module. Patch will follow as soon as possible.
Comment #28
abaier commentedGreat, thank you! I am following the progress and will provide feedback when I've tested it.
Quick question: The tests were all ran against 8.3. Should work fine with 8.2.5, though?!
Comment #29
it-cruAdd a InstagramEmbedFetcher (some parameters missing yet: see - https://www.instagram.com/developer/embedding/#oembed) for getting embed for InstagramEmbedFormatter field formatter with caching.
Display of caption is configurable. InstagramEmbedFormatterTest not testet yet.
Comment #31
it-cruAdd better error handling for InstagramEmbedFetcher. I think tests will currently fail.
Comment #33
chr.fritschI fixed some coding styles, the tests and implemented the ContainerFactoryPluginInterface for InstagramEmbedFormatter.
The hide option should also work now.
Comment #35
chr.fritschAnother round of big changes. I adjusted the MediaEntity\Type\Instagram to also fetch everything from the oembed api. With that we lose the ability to get instagram tags. But we win, that all the other fields are now available without any credentials.
Comment #37
mtodor commentedNice work everyone! This is realty nice improvement. I did code review and everything looks good, I have just few nitpicks.
Nitpick: $hidecaption should be added in Interface as option too, or make it required argument.
We should inject this service: 'http_client'
I think it would be better to inject logger channel and use that, instead of watchdog_ function.
"Hidden" and "Visible" should be translated too.
Nitpick: it would be nice to set cache key in custom variable and use it in both places + wrap $hidecaption in intval(), so that we have nicer format for key when $hidecaption is FALSE ("key_0" instead of "key_").
Small consideration. Maybe static urls can be set in protected static properties ('http://instagr.am/p/' and 'http://api.instagram.com/oembed'). Additionally, I'm not sure can we use https instead of http?
But overall, everything looks great and clean.
Comment #38
chr.fritschAdjusted all the comments from #37
Also:
Comment #40
chr.fritschThe patch is now working pretty good. One thing i noticed, the layout of the posts changed. I have no clue why. Maybe these iframe method is deprecated.
New oembed implementation:

Old iframe implementation:

Comment #41
it-cruPerhaps Instagram change or optimize currently styling of embeded posts. We also see this or other layouts on our projects sometimes.
Also see https://www.instagram.com/developer/embedding/
Comment #42
chr.fritschNew patch to get the correct extension from the filename
Comment #43
tjwelde commentedIt would be nice to pass the shortcode to the template, too. That way, you have more options, to override it, for example for AMP or Facebook Instant Articles.
This patch adds that.
Comment #44
zuernbernhard commentedPatch works like a charm for us. Can we commit it to the module ?
Comment #45
zuernbernhard commentedComment #46
it-cruLoggerChannelFactory should be defined as LoggerChannelFactoryInterface
Comment #47
darrenwh commentedLooks goog
Comment #48
darrenwh commentedLooks good
Comment #49
bkosborneThe oembed request should have a pretty short timeout on it. If the instagram oEmbed endpoint is unresponsive, you don't want to nuke your site performance waiting for eEmbed requests to timeout at the default time (prolly 30 seconds or more).
Comment #50
bkosborneOops, wrong patch.
Comment #53
chr.fritschThanks everyone for the hard work.