shweshi / OpenGraph

A Laravel package to fetch Open Graph data of a website.
https://opengraph.shashi.dev
MIT License
157 stars 29 forks source link

Doesn't get OpenGraph metadata from Instagram #76

Closed jcmlumacad closed 3 years ago

jcmlumacad commented 3 years ago

Tried any shared Instagram links. It returns empty

olavski commented 3 years ago

The default user-agent is 'Curl' so it might be blocked by some websites.

Try adding a different user-agent, for example:

$data = \OpenGraph::fetch(
   "https://www.instagram.com/p/CNnImF-gvkb/", 
   true, 
   null, 
   null, 
   'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
);
shweshi commented 3 years ago

@jcmlumacad can u share the link u were trying to fetch. Also make sure the url is publicly available, and it's available in region u are trying to fetch.

jcmlumacad commented 3 years ago

image

@shweshi Please try this link https://www.instagram.com/p/CNnImF-gvkb I think that's a public URL


I'm expecting something link this result https://developers.facebook.com/tools/debug/?q=https%3A%2F%2Fwww.instagram.com%2Fp%2FCNnImF-gvkb

image

jcmlumacad commented 3 years ago

The default user-agent is 'Curl' so it might be blocked by some websites.

Try adding a different user-agent, for example:

$data = \OpenGraph::fetch(
   "https://www.instagram.com/p/CNnImF-gvkb/", 
   true, 
   null, 
   null, 
   'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36'
);

Why do we need a user agent? Is it not working by default?

shweshi commented 3 years ago

@jcmlumacad Many websites/links blocks the requests coming from the scripts/tools to prevent the scraping. The default user-agent is Curl used in the OpenGraph. Try changing it to one suggested by @olavski and see if that works.

jcmlumacad commented 3 years ago

@shweshi I see. This should work for now. Thanks