Anyone from the wix technical team, can you please look into this?
As part of my custom login module I have been using facebook’s graph API, which has been working fine until it stopped now: My backend code:
The same call works standalone from a browser or as a curl request, but fails from the wix backend.
I have also tried with axios and facebook-node-sdk ( with timeout of upto 30 secs). I receive similar timeout errors only from wix.
Tagging in @shantanukumar847 as I see you had used facebook oauth as part of your custom login in an earlier post. Wondering if you still use it and if it works.
I have raised this with the wix technical support team as well (#211943126)
If so, this is how I get the data from facebook. A button will redirect the user to fb to login and provide access via the **getLink** function. Fb will send the user back to the redirect page along with a code parameter in the URL. Use that code in the **processCode** function to exchange it in return for user data like first name, last name, email and account id
import * as queryString from 'query-string';
import { fetch } from 'wix-fetch';
const stringifiedParams = queryString.stringify({
client_id: 'XXXXXXXXX',
redirect_uri: 'https://www.domain.com/redirect-page',
scope: ['email'].join(','),
response_type: 'code',
auth_type: 'rerequest'
});
export function getLink() {
const facebookLoginUrl = `https://www.facebook.com/v10.0/dialog/oauth?${stringifiedParams}`;
return facebookLoginUrl;
}
export async function processCode(code) {
const response = await fetch(`https://graph.facebook.com/v10.0/oauth/access_token?client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&redirect_uri=https://www.domain.com/redirect-page&code=` + code, {
method: "get"
});
let result = await response.json();
return getBasicDetails(result);
}
async function getBasicDetails(result) {
const response = await fetch("https://graph.facebook.com/me?fields=id,email,first_name,last_name&access_token=" + result.access_token, {
method: "get"
});
let data = await response.json();
return data; // Over here we receive the email, first name, last name and account id from facebook, now how you use that is up to you
}
Thank you Shan, I am doing almost exactly the same. And it was working for about 6 months until it suddenly stopped.
Your ’ processCode ’ method is where it’s failing for me with a time out.
But the same url works fine when I call it from outside of Wix.
Have you had to setup anything on the Facebook developer console (apart from the Client OAuth Settings) to allow these queries originating from WIX?
Thanks Shan.
I have tried afresh with hardcoding all the parameters from a test function.
To be double sure, I ran the same test function from both the server side and client side.
Server side - times out almost always.
Client side - works as expected
curl - works as expected
I am absolutely convinced this is a WIX server side network/firewall/whitelisting issue.
The reason I say this is once out of the blue Yesterday I did get a Facebook error on the serverside and all of it was in Mandarin / Taiwanese.
const response = await fetch ( url , { method : “get” });
let result = await response . json ();
console . log ( "Resilt " , result );
Server side output:
“[“Error “,”{"error":{"code":"ETIMEDOUT","connect":true}}”]”
-or-
“[“WebMethod request timed-out after 14 seconds… Did you forget to resolve a promise?”]”
@shantanukumar847 here is the response I received from Velo Product Support Specialist team
I ran a few quick tests on your site and could see that, indeed, the timeout error appeared a couple of times for me. However, it only happened in the Editor backend functions testing tool, and not on the live site. Kindly note that the functions testing tool is just a local testing tool, and may not reflect the proper functionality when it comes to interacting with browser settings and reaching out to other platforms.
Therefore, I would suggest you to call the function in the frontend, publish your site and try again.
Besides, using aync/await may be convenient for data management, however, it is not the most efficient method when it comes to errors handling. I would recommend using .then() and .catch() blocks instead of async/await, so that we are able to track the errors and their nature.
As a fix, I have moved this call out of Wix as a firebase cloud function.
So my call sequence is :-
Fetch call from wix backend
If successful, proceed
if failure call firebase cloud function & proceed
And oh, btw in my production code I am using .then() and .catch()
wix finally solved this problem for me. Here is their response:
While we were trying to arrange the call, our developers actively continued the investigation process. Eventually, they were able to recreate the issue on their end once, and identify the root cause of it.
They have immediately implemented the fix, and the functionality should work now. Please, let us know if you are still experiencing an issue on your end, since the errors seem to have been connected to the specific IP addresses.