简体   繁体   中英

Sending tokens to Actions On Google returns error "Can't parse the response. The response needs to be JSON format"

Good morning, I am using ASP.NET HTTP API as Actions on Google fullfilment. I have an error message when I try to send tokens to Actions on Google project. Regarding to another question I read I made sure to have clear int value (not decimal) and it doesn't work.

My JSON which I send to Actions on Google:

{"token_type":"Bearer","access_token":"edeaa27e-12b7-43a1-bc7c-e6bbf9af71c3","refresh_token":"4344383b-cf07-4d12-a5c2-44b6481f5f48","expires_in":86400}

Error message:

{
    insertId: "1o7lj2bmu"
    jsonPayload: {
        @type: "type.googleapis.com/google.identity.accountlinking.type.AccountLinkingError"
        errorReason: "Can't parse the response. The response needs to be JSON format."
        response: {
            body: ""{\"token_type\":\"Bearer\",\"access_token\":\"edeaa27e-12b7-43a1-bc7c-e6bbf9af71c3\",\"refresh_token\":\"4344383b-cf07-4d12-a5c2-44b6481f5f48\",\"expires_in\":86400}""
            status: 200
    }
    step: "AUTH_CODE_EXCHANGE"
    }
    logName: "projects/smartlightproject-f47f4/logs/accountlinking-pa.googleapis.com%2Ferror"
    receiveTimestamp: "2022-07-12T12:32:40.739532642Z"
    resource: {2}
    severity: "ERROR"
    timestamp: "2022-07-12T12:32:40.539Z"
}

What's wrong with that JSON? Or maybe I should do it in some other way? I will be very very grateful if you could help me with that.

Here's my code after some improvements:

var result_acceess_token = "edeaa27e-12b7-43a1-bc7c-e6bbf9af71c3";
var result_refresh_token = "4344383b-cf07-4d12-a5c2-44b6481f5f48";
var expires_expires_in = 86400;

var resultObj = new
{
     token_type = "Bearer",
     access_token = result_acceess_token,
     refresh_token = result_refresh_token,
     expires_in = expires_expires_in
};

return Ok(resultObj);

Earlier I tried to serialize JSON with JsonConvert and return it as JsonResult or raw string value.

It looks like the response you're sending back is the JSON as a quoted string. That is - there is a quote at the beginning and end of the JSON. While this is a valid JSON string (it is, after all, a quoted string), it sounds like it is looking for a JSON object.

Verify the body of the response and make sure it does not contain the opening and closing quotes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM