I got the attribute of Undefined error cannot be read in my action creator.
function graphRequest(path, params, token=undefined, version=undefined, method='GET') {
return new Promise((resolve, reject) => {
new GraphRequestManager().addRequest(new GraphRequest(
path,
{
httpMethod: method,
version: version,
accessToken: token
},
(error, result) => {
if (error ) {
console.log('Error fetching data: '+ error);
reject('error making request.' + error);
} else {
console.log ('Success fetching data:');
console.log(result);
resolve(result);
}
},
)).start() ;
});
}
I use my action creator to call the above content
export function accounts() {
return dispatch => {
console.log("fetching accounts!!!!!!"); dispatch(accountsFetch());
fbAPI.accounts().then((accounts) => {
dispatch(accountsFetchSuccess(accounts));
}).catch(( error) => {
dispatch(accountsFetchFailure(error));
})
}
}
I get “Success Get data:” and the result before the error. So the API call completed successfully. The error is after getting the account in fbAPI.accounts(). Then ((account) I think it is because GraphRequestManager returns immediately instead of waiting.
My provider looks like this:
< /p>
FBGraphRequest = async (fields) => {
const accessData = await AccessToken.getCurrentAccessToken();
// Create a graph request asking for user information
return new Promise((resolve, reject) => {
const infoRequest = new GraphRequest('/me', {
accessToken: accessData.accessToken,
parameters: {< br /> fields: {
string: fields
}
}
},
(error, result) => {
if (error) {
console.log('Error fetching data: '+ error. toString());
reject(error);
} else {
resolve(result);
}
});
new GraphRequestManager().addRequest(infoRequest).start();
});
};
triggerGraphRequest = async () => {
let result = await this.FBGraphRequest('id, email');
return result;
}
This is great! I adapt your solution to your system.
Does anyone have an example of how to use GraphRequestManager’s promise?
I got the attribute of Undefined error cannot be read in my action creator.
function graphRequest(path, params, token=undefined, version=undefined, method='GET') {
return new Promise((resolve, reject) => {
new GraphRequestManager().addRequest(new GraphRequest(
path,
{
httpMethod: method,
version: version,
accessToken: token
},
(error, result) => {
if (error ) {
console.log('Error fetching data: '+ error);
reject('error making request.' + error);
} else {
console.log ('Success fetching data:');
console.log(result);
resolve(result);
}
},
)).start() ;
});
}
I use my action creator to call the above content
export function accounts() {
return dispatch => {
console.log("fetching accounts!!!!!!");
dispatch(accountsFetch());
fbAPI.accounts().then((accounts) => {
dispatch(accountsFetchSuccess(accounts));
}).catch((error) = > {
dispatch(accountsFetchFailure(error));
})
}
}
I get “Successfully fetched data: “And the result before the error. So the API call completed successfully. The error is after getting the account in fbAPI.accounts(). Then ((account) I think it is because GraphRequestManager returns immediately instead of waiting.
I have a solution for you.
My provider looks like this:
FBGraphRequest = async (fields) => {
const accessData = await AccessToken.getCurrentAccessToken();
// Create a graph request asking for user information
return new Promise((resolve, reject) => {
const infoRequest = new GraphRequest('/me', {
accessToken: accessData.accessToken,
parameters: {
fields: {
string: fields
}
}
},
(error, result) => {
if (error) {
console.log('Error fetching data: '+ error.toString());
reject(error);
} else {
resolve(result);
}
});
new GraphRequestManager().addRequest(infoRequest).start();
});
};
triggerGraphRequest = async () => {
let result = await this.FBGraphRequest('id, email');
return result;
}
This is great! I adapt your solution to your system.