PokeGOAPI-Java icon indicating copy to clipboard operation
PokeGOAPI-Java copied to clipboard

error parsing GoogleAuthJsonToken with Moshi

Open pompobit opened this issue 10 years ago • 2 comments

I'm parsing a google token apparently valid like this: { "access_token": "ya29.Ci8tAyC0_o8AvEm_FLXfrYUOJOU5dbgkJSjGpm6X3r3Zn9dLlerx1IL8BGpu_Mr_pw", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "1/Hlyav3B17lSYXzEPyUOJ8GTOkgiWRNtUzAzI30Lz-GM", "id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI5IjUwNzgyYmNmMGE5NzQxZTZiZjkwMjY2ZGMzNTY4YWE5MDc5MWYxNmYifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhdF9oYXNoIjoianVrM1AzWDVSWWhJd0huczdQUlFHdyIsImF1ZCI6Ijg0ODIzMjUxMTI0MC03M3JpM3Q3cGx2azk2cGo0Zjg1dWo4b3RkYXQyYWxlbS5hcHBzLmdvb2dsZXVzZXJjb250ZW50LmNvbSIsInN1YiI6IjEwMjQ2MTA1NTI3OTc1OTU2NDY2MiIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhenAiOiI4NDgyMzI1MTEyNDAtNzNyaTN0N3Bsdms5NnBqNGY4NXVqOG90ZGF0MmFsZW0uYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJlbWFpbCI6Impva3VsaGF1cHNza3lAZ21haWwuY29tIiwiaWF0IjoxNDY5NTk0ODg3LCJleHAiOjE0Njk1OTg0ODd9.iZL7uU0x6QIUArB2M6H_m4nd6WINet3TALMCRQhlXrUOofXaBzU09QAOUrImjkvVK5Dl_GHL7YEztVnrzAh6gy3ay0dS2uTel8YBr7M0JkIjHp3Hw2plj6K0-sBz1h7ARCNS0AXfMpyVh_FKFiDI1uz99lOASd0gBs2zxzFpzXTWq0mgDL1onp7gLkS5I7Cy5ZZNkdEVi054KylEXyXjDM5sika9yPXZm0vLcFHcEsnAjs6QqXnI02FS38JRBJxQth6--Pfx8rlRz6o5qD6yKkQ2YDr061bG5XYAsdED9DwGENPBrDXz8bvQd54Mq1UhJKsK_wCmxFPCrgROsOLYTw" }

I tried to use moshi to turn the json in a GoogleAuthTokenJson in this way:

Moshi moshi = new Moshi.Builder().build(); token = moshi.adapter(GoogleAuthTokenJson.class).fromJson(response.body().string());

but it throws an error: com.squareup.moshi java.io.EOFException: End of input

I'm not sure because that is a valid Json. Any idea?

pompobit avatar Jul 27 '16 05:07 pompobit

Need more info abt yr code above that. Have u logged the response before this using response.body().string() before this? If so thats yr issue. Just assign value to variable and u shld be fine.

rajulbhatnagar avatar Jul 27 '16 05:07 rajulbhatnagar

bingo! To find the solution without reading the code is pure genius! I always forget that calling body().string() consumes the body, this is not the first time I get crazy for that. Thank you

pompobit avatar Jul 27 '16 05:07 pompobit