How to get the generated url when accessing the instagram photo link using /media/? size=l at the end

Asked

Viewed 63 times

1

I’m trying to get the url that is displayed (switched) when accessing a link as for example on instagram https://www.instagram.com/p/B9MjyquAfkE/media/? size=l, the link generated after the click, comes from the instagram api, and as this same link generated has expiration time, there is no way to use it for long. Is there any way via php, to catch it without showing the page itself from the link? I tried to use Curl but could not get the result.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '"'.$dadosItemInstagram['imagem'].'"');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ret = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

The $dadosItemInstagram['image'] array contains the link. I’ve been reading a lot before coming here, and so I understood instagram from an account authorization to access their api, for example to display images or videos on websites, except that the link has a certain duration so I’m stuck in this part, the solution I found was to add the /media/?size=l , at the end of the link, so I know if it’s the best too.

1 answer

0


What happens is that this link is redirected to another url, so you need CURL to accept redirects. You can do this by setting the option CURLOPT_FOLLOWLOCATION:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  • It worked very well, but I could only play by putting a link in curl_setopt($ch, CURLOPT_URL, "(um_link_aqui)"); , if I put a variable that contains the link it is not right, I do not know if it is possible too, has this possibility?

  • It is also possible to return only the redirected url?

  • Yes, this is already being done with the function curl_getinfo: $urlRedirecionada = $info['url'];

Browser other questions tagged

You are not signed in. Login or sign up in order to post.