Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cannot get twitter open graph tags #18

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add facebookexternalhit, Bypassing the User-Agent whitelist to receiv…
…e server-side-rendered (SSR) HTML
WingCH committed May 13, 2021
commit b79f5e93807f02b1d61cd3fa2bcb8ff2d40660b8
9 changes: 7 additions & 2 deletions lib/web_analyzer.dart
Original file line number Diff line number Diff line change
@@ -181,14 +181,19 @@ class WebAnalyzer {
final uri = Uri.parse(url);
final ioClient = HttpClient()..badCertificateCallback = _certificateCheck;
final client = IOClient(ioClient);
/*
Twitter website doesn't have open graph tags?
https://stackoverflow.com/a/64332370/5588637
*/
final request = Request('GET', uri)
..followRedirects = false
..headers["User-Agent"] = useDesktopAgent
? "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36"
: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
? "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php) Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36"
: "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php) Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"
..headers["cache-control"] = "no-cache"
..headers["Cookie"] = cookie ?? _cookies[uri.host]
..headers["accept"] = "*/*";

// print(request.headers);
final stream = await client.send(request);