Sample code for 30+ languages & platforms
Rust

Google Search Console API - List

See more Google Search Console Examples

Lists the user's Search Console sites.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

// This example uses a previously obtained access token having permission for the 
// Google Search Console scope.

// In this example, Get a Google Search Console OAuth2 Access Token, the access
// token was saved to a JSON file.  This example fetches the access token from the file..
let json_token = chilkat::JsonObject::new();
let _ = json_token.load_file("qa_data/tokens/googleSearchConsole.json").is_ok();
if !json_token.has_member("access_token") {
    println!("No access token found.");
    return;
}

let http = chilkat::Http::new();
http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());

let Ok(response_str) = http.quick_get_str("https://www.googleapis.com/webmasters/v3/sites") else {
    println!("{}", http.last_error_text());
    return;
};

let status_code = http.last_status();
println!("Response Status Code: {}", status_code);

// Sample response:

// {
//  "siteEntry": [
//   {
//    "siteUrl": "https://www.example.com/",
//    "permissionLevel": "siteUnverifiedUser"
//   },
//   {
//    "siteUrl": "http://www.chilkatsoft.com/",
//    "permissionLevel": "siteOwner"
//   }
//  ]
// }

println!("{}", response_str);

// Use this online tool to generate parsing code from sample JSON: 
// Generate Parsing Code from JSON

let json = chilkat::JsonObject::new();

let _ = json.load(&response_str).is_ok();

let mut site_url = String::new();
let mut permission_level = String::new();

let mut i = 0;
let count_i = json.size_of_array("siteEntry");
while i < count_i {
    json.set_i(i);
    site_url = json.string_of("siteEntry[i].siteUrl").unwrap_or_default();
    println!("siteUrl: {}", site_url);
    permission_level = json.string_of("siteEntry[i].permissionLevel").unwrap_or_default();
    println!("permissionLevel: {}", permission_level);
    i = i + 1;
}