how to test open graph on localhost

TestingFacebook Graph-ApiLocalhost

Testing Problem Overview


I've done a lot of research and haven't found a definitive answer to this. Is there anyway to test the open graph on localhost? I don't haven any issues using the graph api on locahost.

I've changed my website url in the app settings and have even tried setting up a domain in my hosts file but the debugger linter for open graph tries to use the actual domain instead of my localhost and when using locahost directly the linter completely fails connecting.

Does anybody have any workarounds for this?

Testing Solutions


Solution 1 - Testing

Using a local proxy is the right solution. ngrok didn't work for me neither.

A similar tool that did work with facebook debugger is localtunnel

npm install -g localtunnel
lt --port 8000

Generates a url that looks something like https://<random_hash>.localtunnel.me/. Using this url in facebook open graph debugger worked for me as of October 18th 2017. I only had to hit Fetch new scrape information button. 

Cool thing about localtunnel is that you can easily host your own localtunnel server with github.com/localtunnel/server so if it ever stops working with localtunnel.me, you can run your own somewhere in the cloud

Solution 2 - Testing

You can use ngrok to create a random public subdomain that routes to your local webserver very easily, even through NAT or firewalls.

Just download ngrok and run ./ngrok http 8080 (assuming 8080 is your local webserver http port).

This will create a random subdomain like http://38a84a97.ngrok.io/ that routes to your local webserver and that you can use with Facebook to test your open graph tags.

Solution 3 - Testing

Its very simple to test Open Graph in any local environment using Chrome or Firefox using plugins. I have used one to quickly show in chrome how the Open Graph looks to the viewer to test results. Here is a quote of what it does.

> This extension shows how people will see your site in the most popular > social networks This extension is for professionals who creates a > media content. > > To check meta-information of your site or article just open it in a > Chrome and click extension's icon. Also you could add an URL manually.

Here is a direct link to the plugin (Chrome)
Firefox add-on

Solution 4 - Testing

As a bit simpler approach you can use a browser extension like https://socialsharepreview.com/browser-extensions - which will show your Social Cards directly in the Browser (which of course might fail, if you wrongly didn't set them serverside :))

Solution 5 - Testing

To test open graph (and Twitter cards) I also had to expose localhost (Docker) to Facebook and Twitter. I used Serveo

It works very well for this, no need to install anything as it works with ssh port forwarding.

$ ssh -R 80:localhost:3000 serveo.net

Then navigate to the url given, and there you go.

Solution 6 - Testing

You have to setup a public domain which points to your public ip address. Use dynes.org or a similar service and setup your router to forward your port 80.

Solution 7 - Testing

There are several tools you can use for serving something up over your localhost, each with varying degrees of functionality.

I prefer (obviously) http://forwardhq.com

Other great options here: http://devblog.avdi.org/2012/04/27/http-forwarding-services-for-local-facebook-development/

Solution 8 - Testing

If anyone is looking to preview the :og tags on while developing on subdomains (using lvh.me) in localhost. You can use https://serveo.net. Simply use following command to forward your local server requests. No installation required.

ssh -R yoursubdomain.serveo.net:80:yoursubdomain.lvh.me:3000 serveo.net

you can put your desired port in place of 3000.

Reference: https://blog.aarvy.me/2019/09/20/expose-local-apps-having-subdomains-to-web/

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDavidBView Question on Stackoverflow
Solution 1 - TestingGabLeRouxView Answer on Stackoverflow
Solution 2 - TestingIwazaruView Answer on Stackoverflow
Solution 3 - TestingBigEdView Answer on Stackoverflow
Solution 4 - TestingArminView Answer on Stackoverflow
Solution 5 - TestingJesseView Answer on Stackoverflow
Solution 6 - TestingStephan AlberView Answer on Stackoverflow
Solution 7 - TestingJosiahView Answer on Stackoverflow
Solution 8 - TestingRajan Verma - AarvyView Answer on Stackoverflow