costastf / locationsharinglib

A library to retrieve coordinates from an google account that has been shared locations of other accounts.
MIT License
170 stars 29 forks source link

Debugging GgA= in field 6 return code. #112

Closed brewston closed 1 year ago

brewston commented 1 year ago

Hiya

I'm trying to debug why this lib isn't working in HA. I've had multiple attempts to extract cookies (both from Chrome & Firefox) I have some simple test code :

import logging 
logging.basicConfig(level=logging.DEBUG)
from locationsharinglib import Service
google_email = 'myemail@gmail.com'
cookies_file = 'cookies'
service = Service(cookies_file=cookies_file, authenticating_account=google_email)
for person in service.get_all_people():
    print(person)

running in a loop every 30s and within about 10mins, I see GgA= in the return code and it stops working. I extract new cookies, write to the filesystem and it works again. Do you have any tips on how to debug further ? Thanks

costastf commented 1 year ago

Hi, I am afraid there is not much more debugging. If the session gets invalidated then you cannot retrieve info. Do you use an unused other than your main g mail account and leave the session open in the browser? Do you by any chance use gsuite email and there is configuration to invalidate the session after some time by the admin account? Throwing some thoughts out there..

brewston commented 1 year ago

Thanks for quick reply. It is my main gmail account - not gsuite (as my family share with me and don't want HA app on their phones) I normally have a maps session open in my browser. This problem started when I had to clear cache/cookies in FF to fix a problem with a different site. Normally the HA maps integration just works..

costastf commented 1 year ago

I have had some erratic behavior reports from people but it was always something with the cookies. Maybe try another add on?

costastf commented 1 year ago

I have an account just for the location sharing and I share mine and my wife's with that so it never interferes with my actual account that I might log out unintentionally. That is what I suggest you do so you can set up a session and then just close the tab and forget about it.

brewston commented 1 year ago

Is there a recommended best way to extract the cookies ? I've tried 'export cookies' on FF and 'get cookies.txt LOCALLY' on Chrome. Thanks.

costastf commented 1 year ago

What domain are you trying? Please try to log in on maps.google.com . I think that either of those two add ons would work.

brewston commented 1 year ago

maps.google.com just re-directs me to https://www.google.com/maps

costastf commented 1 year ago

I guess that should work then.

brewston commented 1 year ago

Weird, I booted up a different laptop, extracted the cookies there and it seems to be updating OK in HA now. One question regarding HA - is the cookies file only read at HA start time ? it seems that dropping a newer cookies file in place without restarting HA has no effect.

costastf commented 1 year ago

I think that it is only reading them on add on loading, so you have to reload for the new cookies to be read. Happy that your issue is solved!

costastf commented 1 year ago

Is it ok to close this?

brewston commented 1 year ago

Yes, of course. Thanks for your help. Great integration for HA

brewston commented 1 year ago

Closing

brewston commented 1 year ago

@costastf I think the problem might due to a particular cookie __Secure-1PSIDTS

see - https://community.home-assistant.io/t/google-maps-location-sharing-problems/603446/14

if you agree, maybe your code could be adapted to strip it out ?

costastf commented 1 year ago

Sure, if we end up realizing that it is indeed the case. Currently I would like people to try with their text cookies and remove (or comment out with a hash) the __Secure-1PSIDTS and see if that makes a difference. If we end up being very confident that it is the problem we can filter it out on parsing of the file and log a warning about it. Does this make sense?

brewston commented 1 year ago

Yes, perfect sense. Thanks.