From https://developers.facebook.com/docs/instagram/oembed:

This document explains how to use the new Instagram oEmbed endpoint. This endpoint is replacing Instagram's Legacy oEmbed endpoints, which will be deprecated on October 24, 2020.

If you are migrating off of the legacy endpoints, make sure to read this document in its entirety since the endpoint paths and their requirements have changed.

This means the module will need updating to handle the new API.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna created an issue. See original summary.

patrick_mcdougle’s picture

Yeah, this is going to be tricky since the new endpoint isn't unauthenticated and requires a facebook app / developer account / graph API access.

patrick_mcdougle’s picture

FileSize
4.54 KB

Here's a start. Lots more to do, but it's a start. Anyone should feel comfortable applying the patch onto their own branch and take development from here. I don't know if I will ever spend the time required to get this all the way working. It's basically a port of some code I wrote for work and thought I could share with the community.

chr.fritsch’s picture

Thx for starting this. I've seen that @patrick_mcdougle already added a PR for oembed.com. (https://github.com/iamcal/oembed/pull/470)

I think when we have to reimplement the API, it would be nice if we could use as much as possible from drupal core's oEmbed implementation.

chr.fritsch’s picture

Status: Active » Needs review
FileSize
50.56 KB

So here is my proposal. The plan is to get this committed to 3.x soon.

patrick_mcdougle’s picture

That patch looks good to me (code reviewed, but not run), this is arguably better than the direction I was running with. Happy to see that you were able to eliminate some of the cruft and utilize more of the core functionality.

The other thing that we should eventually think about is how to help people transition from v2 to v3 so that things won't break when they upgrade. Was this transition smooth for you? Was it as easy as just replacing the code, or did it break old Instagram Oembeds that were created from v2?

I wish the interfaces in the oembed core component were a little better. It'd be great if the providers could handle their own fetching logic (or fall back to a default one as it does now) as opposed to just brokering endpoints / url building, but that's a fight for another day...

chr.fritsch’s picture

Here is an improved patch that:
- Adds the source as a class instead of the alter hook. This has the advantage that we can remove the fields that are not supported by the graph api
- Adds an update hook

patrick_mcdougle’s picture

One thing that we COULD do instead would be override the media type class. Following the example from the top of the OEmbed class...

function media_entity_instagram_media_source_info_alter(array &$sources) {
  $sources['instagram'] = [
    'class' => 'Drupal\media_entity_instagram\Plugin\media\Source\InstagramOEmbed',
  ];
}

This way we can extend Core's Oembed class, but rewrite the parts that need re-writing. (Including possibly putting the fb app id / secret on the media type config as opposed to the config of this module).

volkerk’s picture

Status: Needs review » Needs work

Looks like a nice simple approach.
Found a few issues tough:

1. Add descriptive error message in hook_oembed_resource_url_alter() implementation, when facebook credentials are not set, currently it fails with "Could not retrieve the oEmbed resource".
2. Add configure link to module page and readme.
3. Thumbnails only work when using core patch from #3071760: [backport] oEmbed system does not remove query strings from local thumbnail filenames.
4. Display of instagram posts is broken; two iframes (.media-oembed-content and .instagram-media) are nested and height is always 150px.
5. In getMetadata() some effort is made to provide a reasonable 'default_name', but default_name_metadata_attribute is set to author_name in annotation.

chr.fritsch’s picture

Status: Needs work » Needs review
FileSize
56.31 KB

Thanks for the review.
I think I addressed all your concerns. Regarding number 4:
I added back the instagram formatter, we had before because Instagram returns an object without a height and the core formatter can not handle that. I know this is kinda insecure, but I don't see another way to fix this.

chr.fritsch’s picture

FileSize
7.86 KB

Here is the interdiff

volkerk’s picture

Status: Needs review » Reviewed & tested by the community

I found another issue which is addressed by #3168301: oEmbed validator should use the urlResolver to get the resource URL.

Anyway this one here looks good to go.

chr.fritsch’s picture

Version: 8.x-2.x-dev » 3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed as 3.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

finaukaufusi’s picture

Hi guys, thanks for providing this patch. Is there're path to backport this patch to work on Drupal 8.6.x instead of Drupal 8.8 and above?

dpi’s picture

d.o didnt link the commit because of the new branch, the commit is here for those looking:

https://git.drupalcode.org/project/media_entity_instagram/-/commit/527a0...