gilesknap / gphotos-sync

Google Photos and Albums backup with Google Photos Library API
Apache License 2.0
2.02k stars 165 forks source link

Stuck in "Please visit URL to authorize..." #370

Closed robex2005 closed 2 years ago

robex2005 commented 2 years ago

Hello,

I've used v2 of gphotos for more than 1 year, all went fine With the new google oauth changes, i've tried to upgrade to v3 Installed v3.0.3 with the linuxuprising tutorial (from scratch), but when i run pipenv run gphotos-sync, i got the url in the terminal for authorization, i've pasted the link in a browser, went thru the steps to authorize, but i have no prompt to enter token in the terminal

Enviroment> Raspberry PI 3 with Debian Buster Terminal looks like this>

root@rPi:~# gphotos-sync --version 3.0.3 root@rPi:~# pipenv run gphotos-sync --skip-files --skip-albums --skip-index /mnt/extra/GPhotos/ Creating a virtualenv for this project… Using /usr/bin/python3 (3.9.2) to create virtualenv… ⠋created virtual environment CPython3.9.2.final.0-32 in 548ms creator CPython3Posix(dest=/root/.local/share/virtualenvs/root-BuDEOXnJ, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv) added seed packages: pip==20.3.4, pkg_resources==0.0.0, setuptools==44.1.1, wheel==0.34.2 activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

Virtualenv location: /root/.local/share/virtualenvs/root-BuDEOXnJ Creating a Pipfile for this project… 07-01 10:11:41 WARNING gphotos-sync 3.0.3 2022-07-01 10:11:41.482256 Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=865149062731-k9rmq5xxxxxxxxxxjl58evn6h44nefii.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fphotoslibrary.readonly+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fphotoslibrary.sharing&state=SmY6Cva0PO5PG9x10X8fwwl1o2DZQ9&access_type=offline

Any advice?

Thanks, Robert

gilesknap commented 2 years ago

I'm afraid the linux uprising instructions are out of date, please refer to https://gilesknap.github.io/gphotos-sync/main/tutorials/installation.html.

The browser should automatically redirect back to local service so it is essential that your browser and gphotos-sync are running on the same machine. There are some workarounds in the docs for coping with headless.

robex2005 commented 2 years ago

I've tried the linuxuprising method after using the official method from the documentation I have no desktop on the pi, so the link is access from another computer

I've run the command: gphotos-sync --skip-files --skip-albums --skip-index /mnt/extra/GPhotos/ but the output is the same, i have no prompt for entering the answer token root@rPi:~# source /root/gphotos_venv/bin/activate (gphotos_venv) root@rPi:~# gphotos-sync --skip-files --skip-albums --skip-index /mnt/extra/GPhotos/ 07-01 10:43:42 WARNING gphotos-sync 3.0.3 2022-07-01 10:43:42.225911 Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=865149062731-k9rmq5aslit5xxxxxxxx44nefii.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2F&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fphotoslibrary.readonly+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fphotoslibrary.sharing&state=RxiavJIeqbHGrAUEj9GFBTqtYPWYyl&access_type=offline

^C07-01 10:47:29 ERROR User cancelled download 07-01 10:47:29 WARNING Done. (gphotos_venv) root@rPi:~#

From documentation: If you are running on a NAS or other headless server you will first need to run locally so that you can do initial login flow with a browser. Then copy /.gphotos.token to the server. For this first run you could use the following options so that no backup is performed: Where can i find the token file to copy (i'm accessing the link form a windows computer)

Thanks,

gilesknap commented 2 years ago

When you run locally you choose a target folder and the .gphotos.token should appear in the root of that folder.

robex2005 commented 2 years ago

Managed to get it working... For anyone having the same problem, the fix is to install and set-up gphotos on windows to (outlined in the how-to guide: https://gilesknap.github.io/gphotos-sync/main/how-to/windows.html), to get a response token after accessing the url from the same windows pc on which installed gphotos-sync... Copied the generated token file to the linux headless server, sync is working

Thanks for the help

gilesknap commented 2 years ago

No worries. If you think the docs could be clearer on this topic then let me know.

cmc0619 commented 2 years ago

I've run into this problem as well and was able to come up with a simple solution. On my windows box I go to an administrative command prompt and enter: netsh interface portproxy add v4tov4 listenport=8080 connectport=8080 connectaddress= netsh interface portproxy add v6tov4 listenport=8080 connectport=8080 connectaddress=

I"m sure only one of these commands is needed but it's a one time thing so I was too lazy to determine which command was the meaningful one.

This creates a NAT entry on my Windows machine where I will connect to Google for authorization directing localhost:8080 to my unraid box at port 8080. You can copy the URL from the remote session from your headless machine when it spits out the auth URL upon initial run and paste it into a web browser on the Windows workstation you are connected from. Or, in Unraids case, from the web console it's actually a link in the workstation browser you can simply click.

When the auth goes through on the Windows machine it redirects to localhost:8080 which is now a NAT forward to your Unraid box, the above command will redirect the request from the Windows machine to the headless machines IP address and you will get a success message and everything starts working. -net needs to be host. bridge will not work.

tl;dr: On headless host, make sure port is passed through to container for tcp/8080 and network is set to host Run commands in bold above from Admin command prompt on Windows workstation Run gphotos-sync /storage on headless remote session Enter URL in Windows web browser. You should see a successful authorization and everything is working away on your headless machine

Thank you for this docker!

gilesknap commented 2 years ago

Thanks @cmc0619 that is a good idea. I'm sure the same could be done on linux with socat or iptables.

Do you think you might like to write up a an RST page on this and contribute? :-)