react-native – 使用GraphRequestManager的promise
发布时间:2020-12-15 09:34:32 所属栏目:百科 来源:网络整理
导读:有没有人有关于如何使用GraphRequestManager的promise的例子? 我得到了无法在我的动作创建者中读取未定义错误的属性. function graphRequest(path,params,token=undefined,version=undefined,method='GET') {return new Promise((resolve,reject) = { new G
有没有人有关于如何使用GraphRequestManager的promise的例子?
我得到了无法在我的动作创建者中读取未定义错误的属性. 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(); }); } 我使用我的动作创建者调用上面的内容 export function accounts() { return dispatch => { console.log("fetching accounts!!!!!!"); dispatch(accountsFetch()); fbAPI.accounts().then((accounts) => { dispatch(accountsFetchSuccess(accounts)); }).catch((error) => { dispatch(accountsFetchFailure(error)); }) } } 我在控制台中获得“成功获取数据:”以及错误之前的结果.因此API调用成功完成.错误是在获取fbAPI.accounts()中的帐户之后.然后((帐户)我认为是由于GraphRequestManager立即返回而不是等待. 解决方法
我有一个解决方案给你.
我的提供者看起来像这样: 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 } } },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; } 这很棒!我让你的解决方案适应你的系统. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |