mobeigi / fb2cal

Fetch Facebook Birthdays events and create an ICS file for use with calendar apps
https://go.mobeigi.com/fb2cal
GNU General Public License v3.0
425 stars 72 forks source link

Facebook BirthdayCometRootQuery offset_month logic is wrong. (No results for December) #97

Closed axtck closed 3 years ago

axtck commented 3 years ago

This is probably not an issue with the code but when I extract the events, I don't get any results for the month december. In the ics file, there are no entries with

DTSTART;VALUE=DATE:202112... or DTSTART;VALUE=DATE:202212...

I extracted them last week (april) What could be causing this?

mobeigi commented 3 years ago

That is interesting, I just ran the script and can confirm what you see here (no December results). The endpoint we use fetches the birthdays 3 months at a time but for Oct, Nov, Dec it seems to be skipping Dec.

Funnily enough the official Facebook page here also has the month of December missing: https://www.facebook.com/events/birthdays/

So look like a new off by 1 bug Facebook introduced. I've reported the bug to them, hopefully they can fix it.

axtck commented 3 years ago

Strange indeed, let we know if you get an answer!

adilsond commented 3 years ago

The results for december is back. But the problem now is for the current month. When I get all birthdays from december, all results from june is gone last month. Today, all results from june is back for 2022 but it erases all birthdays from july.

Now this bug makes this script useless :/

mobeigi commented 3 years ago

Not quite sure what Facebook is doing as it seems the offset logic is still quite broken but we can implement a workaround for now.

Previously we had the following code: for offset_month in [1, 4, 7, 10]:

Which would give you the next 3 months of Birthdays starting from the current month. With 4 requests we got all the birthdays for the following year.

After the recent Facebook changes the query had odd logic for the offset_month.

As of July 2021:

0 July, Aug, Sept 1 Aug, Sept, Oct 2 Sept, Oct, Nov 3 Oct, Nov, Dec 4 Nov, Dec, Jan 5 Dec, Jan, Feb 6 Jan, Feb, March 7 Jan, Feb, March 8 Feb, March, April 9 March, April, May 10 April, May, June

Notice how the offset_months for 6 and 7 overlap (which is wrong). If you use the Facebook birthday page https://www.facebook.com/events/birthdays/ and scroll down enough you'll see that one month will be missing at the end of next year (in this case June 2022 is missing which is the offset 11 from July 2021).

So as a workaround we're going to do this and get some overlapping datasets at the expense of 1 extra request but we don't store duplicates in our set so the final result is correct.

# TODO: See #97, offset_month of 10 is needed here because offset months 6/7 are currently returning equivalent months
for offset_month in [0, 3, 6, 9, 10]:

Anyway, this has been fixed with a workaround in https://github.com/mobeigi/fb2cal/pull/103 It will may break again when Facebook changes their API again so we can make a new issue when that happens.