我目前正在通过 fetch in expo 提出这个请求
const response = await fetch(`https://graph.facebook.com/v2.9/{{{i need to enter the id here}}}/friends?access_token=${token}`);
我有 user.id 但我不确定如何在字符串中调用 id
这是整个函数,除了字符串中的 {id} 外,一切正常
login = async () => {
const ADD_ID = '<APP ID>'
const options = {
permissions: ['public_profile', 'email', 'user_friends'],
}
const {type, token} = await Expo.Facebook.logInWithReadPermissionsAsync(ADD_ID, options)
if (type === 'success') {
const response = await fetch(`https://graph.facebook.com/me?access_token=${token}`)
const user = (await response.json());
const id = user.id;
console.log(user);
console.log(id);
this.authenticate(token)
}
try {
const response = await fetch(`https://graph.facebook.com/v2.9/{id}/friends?access_token=${token}`);
console.log(await response.json())
} catch(error) {
console.error(error);
}
}