Mac上でQGISから直接GEE(Google earth engine)を動かす方法

## 概要
研究においてQGISを用いた空間情報分析が必要となったのですが、QGIS⇄GEE(Google earth engine、以下GEE)間のデータ利用を一つのプラットフォームで行いたいと思いGEE Plug-inを導入しました。
この導入過程において、GEE APIの認証でエラーが起きたのでどのように解消したかメモを残しておきます。
バージョン情報は以下です。
`Mac os：Sonoma 14.0`
`QGIS:3.36.3`

## 参考資料
- [GEE Plug-inの設定方法](https://labo-code.com/python/qgis-gee-python/)
- [エラー対処法：Authentication error when initializing Google EE in QGIS 3.16.1](https://gis.stackexchange.com/questions/381116/authentication-error-when-initializing-google-ee-in-qgis-3-16-1)
- [Google Cloud SDK(gcloud) を Homebrew 経由で Mac にインストールする方法](https://zenn.dev/rabee/articles/gcloud-setup-with-homebrew-on-mac)
## 解決方法
基本的な流れとしては、[GEE Plug-inの設定方法](https://labo-code.com/python/qgis-gee-python/)に従ってインストールを行います。
私の場合は、GEE API の認証を試みた際に gcloud コマンドのインストールをしていませんでした。
結果、[エラー対処法：Authentication error when initializing Google EE in QGIS 3.16.1](https://gis.stackexchange.com/questions/381116/authentication-error-when-initializing-google-ee-in-qgis-3-16-1)と同様の以下のエラーが出ました。
```
ee.Authenticate()
To authorize access needed by Earth Engine, open the following URL in a web browser and follow the instructions. If the web browser does not start automatically, please manually browse the URL below.

https://accounts.google.com/o/oauth2/auth?client_id=517222506229-vsmmajv00ul0bs7p89v5m89qs8eb9359.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fearthengine+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&code_challenge=plLB7m2RVrMuL4tLJn9tyYmTrd4IgHw80v7VpwDJs6E&code_challenge_method=S256

The authorization workflow will generate a code, which you should paste in the box below. 
Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.16\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:\Users\hogan\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee\__init__.py", line 86, in Authenticate
    oauth.authenticate(authorization_code, quiet, code_verifier)
  File "C:\Users\hogan\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee\oauth.py", line 233, in authenticate
    _obtain_and_write_token(None, code_verifier)  # Will prompt for auth_code.
  File "C:\Users\hogan\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee\oauth.py", line 137, in _obtain_and_write_token
    auth_code = input('Enter verification code: ')
RuntimeError: input(): lost sys.stdin
ee.Initialize()
Traceback (most recent call last):
  File "C:\Users\hogan\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee\data.py", line 230, in get_persistent_credentials
    tokens = json.load(open(oauth.get_credentials_path()))
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\hogan/.config/earthengine/credentials'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.16\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:\Users\hogan\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee\__init__.py", line 114, in Initialize
    credentials = data.get_persistent_credentials()
  File "C:\Users\hogan\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee\data.py", line 241, in get_persistent_credentials
    'Please authorize access to your Earth Engine account by '
ee.ee_exception.EEException: Please authorize access to your Earth Engine account by running

earthengine authenticate

in your command line, and then retry.
import ee
print(ee.__version__)
0.1.224
ee.Authenticate()
To authorize access needed by Earth Engine, open the following URL in a web browser and follow the instructions. If the web browser does not start automatically, please manually browse the URL below.

    https://accounts.google.com/o/oauth2/auth?client_id=517222506229-vsmmajv00ul0bs7p89v5m89qs8eb9359.apps.googleusercontent.com&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fearthengine+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&code_challenge=_U4vCbBK3y96M4NCHviaxUyuuSOtaXf_z3USrh6xucA&code_challenge_method=S256

The authorization workflow will generate a code, which you should paste in the box below. 
Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.16\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:\Users\hogan\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee\__init__.py", line 86, in Authenticate
    oauth.authenticate(authorization_code, quiet, code_verifier)
  File "C:\Users\hogan\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee\oauth.py", line 233, in authenticate
    _obtain_and_write_token(None, code_verifier)  # Will prompt for auth_code.
  File "C:\Users\hogan\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\ee_plugin\extlibs_windows\ee\oauth.py", line 137, in _obtain_and_write_token
    auth_code = input('Enter verification code: ')
RuntimeError: input(): lost sys.stdin"　
```
このエラー解消のために、homebrew経由でGoogle Cloud SDK(gcloud)をインストールしました。
詳しい内容については、[Google Cloud SDK(gcloud) を Homebrew 経由で Mac にインストールする方法](https://zenn.dev/rabee/articles/gcloud-setup-with-homebrew-on-mac)をご参照ください。
インストールが完了したのち、再度`ee.Authenticate()`実行するとGEEのAPI連携画面が出てきて、認証が実行されるはずです。