From 006c916168bdb1d414de124e6215fbb90ebecc0b Mon Sep 17 00:00:00 2001 From: theBreadCompany Date: Wed, 25 Sep 2024 18:41:49 +0200 Subject: [PATCH] change user agent to prevent cloudflare challenge --- .cargo/config.toml | 2 +- libpixiv/src/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index a659325..02ad3fd 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [env] -PIXIV_REFRESH_TOKEN = "" \ No newline at end of file +PIXIV_REFRESH_TOKEN = "B9bXXiAYctW0s7JfhwHDAlhbVsz8w6Pjz4wDqJsV6Dg" diff --git a/libpixiv/src/lib.rs b/libpixiv/src/lib.rs index c196dee..4d2192a 100644 --- a/libpixiv/src/lib.rs +++ b/libpixiv/src/lib.rs @@ -51,7 +51,7 @@ impl PixivAppClient { let req = self.http_client .post("https://oauth.secure.pixiv.net/auth/token") .header(CONTENT_TYPE, "application/x-www-form-urlencoded") - .header(USER_AGENT, "PixivAndroidApp/5.0.115 (Android 6.0; PixivBot)") + .header(USER_AGENT, "PixivIOSApp/7.6.2 (iOS 12.2; iPhone9,1)") .header(HeaderName::from_lowercase(b"x-client-time").unwrap(), &time_str) .header(HeaderName::from_lowercase(b"x-client-hash").unwrap(), hash) .body(format!("grant_type=refresh_token&client_id={}&refresh_token={}&client_secret={}&get_secure_url=1", client_id, cloned_refresh_token_str, client_secret)) @@ -62,6 +62,7 @@ impl PixivAppClient { Ok(r) => r.text().await.unwrap(), Err(_e) => return, }; + let d: Value = serde_json::from_str(&r).unwrap(); assert!(!d["response"]["access_token"].is_null());