possible anonymous fix?

This commit is contained in:
Austin Huang 2021-06-19 17:25:40 -04:00
parent dcd00ce60b
commit 808c841e65
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
2 changed files with 29 additions and 8 deletions

View File

@ -8,15 +8,15 @@ interface GraphQLService {
@GET("/graphql/query/")
suspend fun fetch(@QueryMap(encoded = true) queryParams: Map<String, String>): String
@GET("/{username}/?__a=1")
@GET("/{username}/")
suspend fun getUser(@Path("username") username: String): String
@GET("/p/{shortcode}/?__a=1")
suspend fun getPost(@Path("shortcode") shortcode: String): String
@GET("/explore/tags/{tag}/?__a=1")
@GET("/explore/tags/{tag}/")
suspend fun getTag(@Path("tag") tag: String): String
@GET("/explore/locations/{locationId}/?__a=1")
@GET("/explore/locations/{locationId}/")
suspend fun getLocation(@Path("locationId") locationId: Long): String
}

View File

@ -1,16 +1,17 @@
package awais.instagrabber.webservices
import android.util.Log
import awais.instagrabber.models.enums.FollowingType
import awais.instagrabber.repositories.GraphQLService
import awais.instagrabber.repositories.responses.*
import awais.instagrabber.utils.Constants
import awais.instagrabber.utils.ResponseBodyUtils
import awais.instagrabber.utils.extensions.TAG
import com.google.gson.Gson
import org.json.JSONException
import org.json.JSONObject
import java.util.*
class GraphQLRepository(private val service: GraphQLService) {
// TODO convert string response to a response class
@ -179,8 +180,16 @@ class GraphQLRepository(private val service: GraphQLService) {
username: String,
): User {
val response = service.getUser(username)
val body = JSONObject(response)
val userJson = body.getJSONObject("graphql").getJSONObject(Constants.EXTRAS_USER)
val body = JSONObject(response
.split("<script type=\"text/javascript\">window._sharedData = ", false, 2).get(1)
.split("</script>", false, 2).get(0)
.trim().replace(Regex("};$"), "}"))
val userJson = body
.getJSONObject("entry_data")
.getJSONArray("ProfilePage")
.getJSONObject(0)
.getJSONObject("graphql")
.getJSONObject(Constants.EXTRAS_USER)
val isPrivate = userJson.getBoolean("is_private")
val id = userJson.optLong(Constants.EXTRAS_ID, 0)
val timelineMedia = userJson.getJSONObject("edge_owner_to_timeline_media")
@ -231,7 +240,13 @@ class GraphQLRepository(private val service: GraphQLService) {
tag: String,
): Hashtag {
val response = service.getTag(tag)
val body = JSONObject(response)
val body = JSONObject(response
.split("<script type=\"text/javascript\">window._sharedData = ", false, 2).get(1)
.split("</script>", false, 2).get(0)
.trim().replace(Regex("};$"), "}"))
.getJSONObject("entry_data")
.getJSONArray("TagPage")
.getJSONObject(0)
.getJSONObject("graphql")
.getJSONObject(Constants.EXTRAS_HASHTAG)
val timelineMedia = body.getJSONObject("edge_hashtag_to_media")
@ -249,7 +264,13 @@ class GraphQLRepository(private val service: GraphQLService) {
locationId: Long,
): Location {
val response = service.getLocation(locationId)
val body = JSONObject(response)
val body = JSONObject(response
.split("<script type=\"text/javascript\">window._sharedData = ", false, 2).get(1)
.split("</script>", false, 2).get(0)
.trim().replace(Regex("};$"), "}"))
.getJSONObject("entry_data")
.getJSONArray("LocationsPage")
.getJSONObject(0)
.getJSONObject("graphql")
.getJSONObject(Constants.EXTRAS_LOCATION)
// val timelineMedia = body.getJSONObject("edge_location_to_media")