From 0950da98e140de76feba63c1eab04a3048aa783e Mon Sep 17 00:00:00 2001 From: akaessens <24660231+akaessens@users.noreply.github.com> Date: Sat, 29 Aug 2020 12:28:28 +0200 Subject: [PATCH] use correct user agent and add legal info --- app/src/main/assets/about.html | 2 ++ .../java/com/akdev/nofbeventscraper/FbScraper.java | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/assets/about.html b/app/src/main/assets/about.html index 1097230..f1450d3 100644 --- a/app/src/main/assets/about.html +++ b/app/src/main/assets/about.html @@ -4,6 +4,8 @@

Open Source

The source code for this application is available at GitHub.

If you encounter an issue, please report it to me anonymously at the Bugtracker or directly at GitHub.

+

Legal

+

This application is intended for saving single, publicly available events into a personal calendar. Do not use it to automatically collect data and comply with facebook's Automated Data Collection Terms.

Donations

I develop this application in my free time. If you like it, you can donate at PayPal.

\ No newline at end of file diff --git a/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java index f39a6f7..2715624 100644 --- a/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java +++ b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java @@ -192,8 +192,13 @@ public class FbScraper extends AsyncTask { try { String url = fixURI(input_url); - // useragent needed with Jsoup > 1.12 - Document document = Jsoup.connect(url).userAgent("Mozilla").get(); + // use correct system user agent because of facebook ToS + String user_agent = System.getProperty("http.agent"); + Document document = Jsoup.connect(url).userAgent(user_agent).get(); + + if (document == null) { + throw new IOException(); + } String json = document .select("script[type = application/ld+json]") .first().data(); @@ -219,6 +224,9 @@ public class FbScraper extends AsyncTask { } catch (IOException e) { e.printStackTrace(); this.error = "Error: Unable to connect."; + } catch (Exception e) { + e.printStackTrace(); + this.error = "Error: Unknown Error."; } return null;