use*_*053 5 post facebook ios react-native
我正在尝试使用fetch向Facebook Graph API发送GET请求:
var url = "https://graph.facebook.com/v2.7/"
+FACEBOOK_APP_ID
+"?fields=context"
+"{friends_using_app{id,name,picture.type(normal)}}"
+"&access_token="+_this.props.user.facebook_access_token;
fetch(url)
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson);
})
.catch(function(error) {
console.log(error);
});
Run Code Online (Sandbox Code Playgroud)
但是我进入TypeError: Network request failed(…)了JavaScript控制台.这只发生在iOS上,它在Android上运行良好.
据我所知,iOS on react native默认允许HTTPS请求,因此不需要任何配置.
我能够使用https://google.com发出请求fetch,并且当我打印urlvar并直接粘贴它时,我能够在safari中查看上述请求的结果.
似乎没有找到类似的东西,但如果这是重复的话,很抱歉.
也许,重试可能会起作用:
static sendCard(card, account, retries) {
return (dispatch, getStore) => {
if (retries && retries > 1) {
return;
}
fetch(apiUrls.sendCardUrl, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Api-Key': account.token,
},
body: JSON.stringify({
card
})
})
.then(response => {
// do something
})
.catch(err => {
// retry again!
retries = retries || 0;
retries++;
setTimeout(() => {
CardActions.sendCard(card, account, retries);
}, 1000);
});
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2964 次 |
| 最近记录: |