oscarotero / Embed

Get info from any web service or page
MIT License
2.08k stars 310 forks source link

Oembed Read API changes #456

Closed arifje closed 2 years ago

arifje commented 2 years ago

Will the deprecation of the old Oembed API from Facebook and update to Oembed Read will effect this plugin? Trying to some things clear on Facebook & Instagram embeds.

oscarotero commented 2 years ago

Facebook and Instagram have a custom OEmbed classes:

I'm not familiarized with the latest changes of Oembed API from Facebook, so let me know if it requires to make some changes here.

arifje commented 2 years ago

Links:

https://developers.facebook.com/docs/plugins/oembed/ https://developers.facebook.com/docs/features-reference/oembed_read

Screenshot 2021-09-29 at 13 40 27

Edit: the reason I post this is because a plugin that we use, uses this library to grab instagram embed data, but it has stopped working. Don't know if this is because of a new app review that has to be made on Facebook developers portal, or if the API also has changed.

nicolas-t commented 2 years ago

Hello,

After submitting my app for "App Review" it's been approved and I'm able to use the current endpoint to retrieve data : 'https://graph.facebook.com/v8.0/instagram_oembed'

The problem is that Embed follows the redirection and try to read oEmbed data from the page https://www.instagram.com/accounts/login instead of https://www.instagram.com/p/myPostId

image

oscarotero commented 2 years ago

I don't have any access token to reproduce this error.

The redirect (here https://github.com/oscarotero/Embed/blob/master/src/Embed.php#L71) only happens if oEmbed is empty (here: https://github.com/oscarotero/Embed/blob/master/src/Embed.php#L83).

If you detect the origin of the problem and want to work on a pull request, i'd appreciate that. Thanks!

nicolas-t commented 2 years ago

Thanks,

It's not easy to debug for me, but it seems that here : https://github.com/oscarotero/Embed/blob/59516a716c9973960fdcf46ba4b6d1b1b801ddc3/src/Embed.php#L67

$this->crawler->getResponseUri($response) is :

Laminas\Diactoros\Uri^ {#4122
  #allowedSchemes: array:2 [
    "http" => 80
    "https" => 443
  ]
  -scheme: "https"
  -userInfo: ""
  -host: "www.instagram.com"
  -port: null
  -path: "/accounts/login/"
  -query: ""
  -fragment: ""
  -uriString: null
}

While $request->getUri() is :

Laminas\Diactoros\Uri^ {#4116
  #allowedSchemes: array:2 [
    "http" => 80
    "https" => 443
  ]
  -scheme: "https"
  -userInfo: ""
  -host: "www.instagram.com"
  -port: null
  -path: "/p/CFUGIUvoCwU/"
  -query: ""
  -fragment: ""
  -uriString: "https://www.instagram.com/p/CFUGIUvoCwU/"
}

So in my understanding the $uri is wrong (redirected) even before calling the function mustRedirect

oscarotero commented 2 years ago

@nicolas-t Ok, thanks This bug was fixed in Facebook adapter here: https://github.com/oscarotero/Embed/blob/master/src/Adapters/Facebook/OEmbed.php#L24-L29

Could you implement something similar for Instagram here? https://github.com/oscarotero/Embed/blob/master/src/Adapters/Instagram/OEmbed.php#L21

nicolas-t commented 2 years ago

Unfortunately there is no next query string for instagram, the url is simply https://www.instagram.com/accounts/login/

oscarotero commented 2 years ago

Maybe it's in the initial Url with $this->extractor->getRequest()->getUri()

oscarotero commented 2 years ago

This is fixed in 4.3.5.