Crates.io | google-api-rust-client-unoffical |
lib.rs | google-api-rust-client-unoffical |
version | 0.1.5 |
source | src |
created_at | 2024-06-24 09:52:17.459741 |
updated_at | 2024-07-13 07:13:24.038046 |
description | An unoffical client library for Google APIs. |
homepage | |
repository | https://github.com/0Itsuki0/google-api-rust-client.git |
max_upload_size | |
id | 1282087 |
size | 138,103 |
An unoffical client library for Google APIs.
crate.io: google-api-rust-client-unoffical
Run the following Cargo command in your project directory:
cargo add google-api-rust-client-unoffical
Or add the following line to your Cargo.toml:
google-api-rust-client-unoffical = "0.1.5"
Obtain Service Account credentials or API Key from APIs & Services > Credentials in the Google Cloud Console.
let filepath: PathBuf = PathBuf::from_str("credentials.json")?;
let credentials = ServiceAccountCredentials::from_service_account_file(filepath)?;
let credentials_json = serde_json::json!({
"type": "service_account",
"project_id": "xxx",
"private_key_id": "xxx",
"private_key": "-----BEGIN PRIVATE KEY-----\nsome_key\n-----END PRIVATE KEY-----\n",
"client_email": "xxx@example.com",
"client_id": "xxx",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/xxx",
"universe_domain": "googleapis.com"
}).to_string();
let credentials = ServiceAccountCredentials::from_service_account_info(credentials_json)?;
let scoped_credentials = credentials.with_scopes(vec!["https://www.googleapis.com/auth/cloud-translation"]);
let subjected_crentials = credentials.with_subject("itsuki@example.com");
let token = credentials.get_access_token().await?;
let mut translation_service = TranslateService::new_with_credentials(credentials);
let response = translation_service.list_languages(Some("ja"), None).await?;
To use API keys, pass them in when creating service objects.
let api_key = env::var("API_KEY")?;
let mut translation_service = TranslateService::new_with_api_key(api_key);
let response = translation_service.list_languages(Some("ja"), None).await?;
Refer to auth.rs for authorization example.
Supported APIs
Refer to translate_service.rs for usage examples.
Supported APIs
Compute Route: Get a route between a start and an end point for different modes of transportation, such as walking, biking, or different types of vehicles. You can also request route details such as distance, estimated time to navigate the route, expected tolls, and step-by-step instructions to navigate the route.
Compute Route Matrix: Get a matrix of information for recommended routes between multiple start and end points, including distance and estimated arrival times.
Refer to route_service.rs for usage examples.