google-indexing-api 1.0.0

GoogleIndexing API
Documentation
use yup_oauth2::{AccessToken};
use google_indexing_api::{GoogleIndexingApi, UrlNotificationsType};


async fn test_token() -> AccessToken {
    // 認証
    let secret = yup_oauth2::read_service_account_key("./test.json")
        .await
        .expect("test.json");
    let auth = yup_oauth2::ServiceAccountAuthenticator::builder(secret).build().await.unwrap();
    let scopes = &["https://www.googleapis.com/auth/indexing"];

    let token = auth.token(scopes).await;
    assert!(token.is_ok(), "{}", token.err().unwrap().to_string());
    token.unwrap()
}

#[tokio::test]
async fn test_sitemaps() {
    let token = test_token().await;
    let a = GoogleIndexingApi::url_notifications().batch(
        token.token().unwrap(),
        vec![
            "http://example.com/widgets/1".to_string(),
            "http://example.com/widgets/2".to_string(),
        ],
        UrlNotificationsType::UPDATED
    ).await;
    assert!(a.is_ok(), "{}", a.err().unwrap().to_string());

    for value in a.unwrap(){
        println!("{} {:?}",value.url(),value.json());
    }
}