當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R googledrive drive_auth_configure 編輯和查看身份驗證配置

drive_auth() 相比,這些函數可以對身份驗證配置提供更多控製和可見性。 drive_auth_configure() 讓用戶指定自己的:

  • OAuth客戶端,在獲取用戶token時使用。

  • API key 。如果通過 drive_deauth() 取消對 googledrive 的授權,則所有請求都將使用 API key 而不是令牌發送。

vignette("get-api-credentials", package = "gargle")了解更多。如果用戶未配置這些設置,則使用內部默認值。

drive_oauth_client()drive_api_key() 分別檢索當前配置的 OAuth 客戶端和 API key 。

用法

drive_auth_configure(client, path, api_key, app = deprecated())

drive_api_key()

drive_oauth_client()

參數

client

一個 Google OAuth 客戶端,大概是通過 gargle::gargle_oauth_client_from_json() 構建的。但請注意,最好使用 path 參數通過 JSON 指定客戶端。

path

Google Cloud Console 下載的 JSON,包含客戶端 ID 和 key ,采用 jsonlite::fromJSON()txt 參數支持的形式之一(通常是文件路徑或 JSON 字符串)。

api_key

API key 。

app

[Deprecated]替換為client爭論。

  • drive_auth_configure() :R6 類 gargle::AuthState 的對象,不可見。

  • drive_oauth_client() :當前用戶配置的 OAuth 客戶端。

  • drive_api_key() :當前用戶配置的 API key 。

也可以看看

其他驗證函數:drive_auth()drive_deauth()drive_scopes()

例子

# see and store the current user-configured OAuth client (probaby `NULL`)
(original_client <- drive_oauth_client())
#> NULL

# see and store the current user-configured API key (probaby `NULL`)
(original_api_key <- drive_api_key())
#> NULL

# the preferred way to configure your own client is via a JSON file
# downloaded from Google Developers Console
# this example JSON is indicative, but fake
path_to_json <- system.file(
  "extdata", "client_secret_installed.googleusercontent.com.json",
  package = "gargle"
)
drive_auth_configure(path = path_to_json)

# this is also obviously a fake API key
drive_auth_configure(api_key = "the_key_I_got_for_a_google_API")

# confirm the changes
drive_oauth_client()
#> <gargle_oauth_client>
#> name: a_project_d1c5a8066d2cbe48e8d94514dd286163
#> id: abc.apps.googleusercontent.com
#> secret: <REDACTED>
#> type: installed
#> redirect_uris: http://localhost
drive_api_key()
#> [1] "the_key_I_got_for_a_google_API"

# restore original auth config
drive_auth_configure(client = original_client, api_key = original_api_key)
源代碼:R/drive_auth.R

相關用法


注:本文由純淨天空篩選整理自Jennifer Bryan等大神的英文原創作品 Edit and view auth configuration。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。