Rust
Rust
Google Search Console API - Add
See more Google Search Console Examples
Demonstrates how to add a site to the set of the user's sites in Search Console.Chilkat Rust Downloads
// 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 sb_url_to_add = chilkat::StringBuilder::new();
let _ = sb_url_to_add.append("https://www.example.com/");
let _ = sb_url_to_add.encode("url", "utf-8");
let sb_url = chilkat::StringBuilder::new();
let _ = sb_url.append("https://www.googleapis.com/webmasters/v3/sites/");
let _ = sb_url.append_sb(&sb_url_to_add);
// Our URL looks like this: https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fwww.example.com%2F
println!("{}", sb_url.get_as_string().unwrap_or_default());
let url = sb_url.get_as_string().unwrap_or_default();
let resp = chilkat::HttpResponse::new();
if http.http_no_body("PUT", &url, &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
let status_code = resp.status_code();
println!("Response Status Code: {}", status_code);
if status_code >= 400 {
println!("{}", resp.body_str());
println!("Failed.");
}
println!("Success");