Facebook graph API me endpoint errors out the first time and successful the next time

149 views Asked by At

I am using facebook login in my coldfusion application. I went through all the steps to get access_token. I am making cfhttp call to "/me" endpoint with access_token and fields parameters and getting "I/O Exception: peer not authenticated" error in the response/Errordetail. I made the same cfhttp call again and able to get successful response of id and name mentioned in fields parameters.

I am expecting the successful response in the first call but have to call twice, so the first call errors out and second one succeeds.

Any help on how to debug or find the issue with the first call. so i should be making one call and get a successful response of current user's information.

i should be making one call and get a successful response of current user's information

<cfscript>

try {
    cfoauth(type = 'facebook', clientid = appId, secretkey = appSecret, result = "res", scope = "public_profile, email", redirecturi = redirectUri);
} catch (any e) {
   writeOutput(e);
}

if (code NEQ "" && res.access_token != "") { // code is a parameter I get from url redirect after cfoauth response
    try {
        cfhttp(method = "GET", charset = "utf-8", url = "https://graph.facebook.com/v17.0/me", result = "fbmeresponse") {
            cfhttpparam(name = "access_token", type = "url", value = res.access_token);
            cfhttpparam(name = "fields", type = "url", value="first_name,last_name,email");
            
        }
        dresponse = deserializeJSON(fbmeresponse.filecontent);
        accessToken = dresponse.access_token;
        writedump(accessToken);

    } catch (any e) {
        writeoutput(e);
    }
 }
</cfscript>
0

There are 0 answers