使用rgee调用GEE时出现授权错误400的求助
rgee对接Google Earth Engine授权Error 400问题解决
问题详情
已执行install.packages("rgee", dependencies = T)完成rgee安装,但运行ee_Initialize()时,授权窗口弹出以下错误:
Error 400: invalid_request The version of the app you're using doesn't include the latest security features to keep you protected. Please make sure to download from a trusted source and update to the latest, most secure version.
环境信息
R/Python包
- R版本:4.1.2 (2021-11-01) -- "Bird Hippie"
- Python版本:3.8
- rgee版本:1.1.3
- reticulate版本:1.25
系统
- 2020 MacBook Pro M1
- macOS Monterey 12.4
- R Studio版本:2022.07.0 Build 548
解决步骤
1. 更新rgee到最新版本
旧版本rgee的OAuth配置可能不兼容Google最新安全规则,先更新包:
install.packages("rgee", dependencies = TRUE) # 若CRAN版本不是最新,可从GitHub安装开发版 devtools::install_github("r-spatial/rgee")
2. 更新Python依赖的earthengine-api
rgee依赖Python的earthengine-api,确保该包为最新版:
# 指定你的Python 3.8路径(可通过终端`which python3`查看) reticulate::use_python("/usr/bin/python3", required = TRUE) # 更新earthengine-api reticulate::py_install("earthengine-api", upgrade = TRUE)
3. 改用离线授权方式
如果在线授权窗口持续报错,试试离线授权:
- 打开终端,运行以下命令完成Python端的GEE授权:
按提示完成授权,生成本地凭证文件。earthengine authenticate - 回到R中,用离线模式初始化rgee:
library(rgee) ee_Initialize(user = "你的Google邮箱地址", drive = FALSE, gcs = FALSE, auth_mode = "offline")
4. 检查并重置网络设置
若R Studio使用代理导致授权请求异常,可临时清空代理设置:
Sys.setenv(http_proxy = "", https_proxy = "")
也可以在R Studio的「工具→全局选项→包」中,取消代理相关勾选。
5. 重置rgee的配置缓存
如果之前的配置有残留,先清理再重新初始化:
ee_clean_credentials() ee_clean_pyenv() ee_Initialize()
内容的提问来源于stack exchange,提问作者Miles
相关产品推荐
相关产品推荐

