Однако я получаю сообщение об ошибке: «com.facebook.react.bridge.ReadableNativeMap невозможно привести к java.lang». .string», хотя я вижу, что результат кода кажется правильным, за 1 секунду до появления ошибки....
Вот мой код:
Код: Выделить всё
// Fetch user profiles and posts from Google Drive
const getUserProfilesFromGoogleDrive = async (accessToken) => {
try {
const deviceID = await AsyncStorage.getItem('deviceID');
let last4Chars = deviceID ? deviceID.slice(-4) : null;
if (!last4Chars) {
console.error('No deviceID found');
return;
}
const fileResponse = await axios.get('https://www.googleapis.com/drive/v3/files', {
headers: { Authorization: `Bearer ${accessToken}` },
params: { q: "name='user-profiles.json'", fields: 'files(id,name)' }
});
const fileId = fileResponse.data.files[0]?.id;
if (!fileId) {
console.error('File not found');
return;
}
const downloadResponse = await axios.get(`https://www.googleapis.com/drive/v3/files/${fileId}?alt=media`, {
headers: { Authorization: `Bearer ${accessToken}` },
responseType: 'arraybuffer'
});
const text = Buffer.from(downloadResponse.data).toString('utf-8');
let profiles = JSON.parse(text);
const matchedProfiles = profiles.filter(profile =>
profile.followerDetails?.includes(last4Chars)
);
if (!matchedProfiles.length) {
console.log('No profiles found');
return;
}
let allUserMemes = [];
for (const profile of matchedProfiles) {
profile.posts?.forEach(post => {
console.log(`Downloading post: ${post.fileName}`);
allUserMemes.push(post);
// Download the post's image (file specific to the post)
downloadPostFromDrive(post.fileName, post.driveId, accessToken);
});
}
setUserPosts(allUserMemes);
} catch (error) {
console.error('Error fetching profiles:', error);
}
};
Поэтому, пожалуйста, взгляните на мой код и скажите мне, что не так, я был бы очень признателен, так как потратил на это целый день
Подробнее здесь: https://stackoverflow.com/questions/793 ... ang-string
Мобильная версия