Search code examples
iosreact-nativefacebook-sharereact-native-fbsdkfbsdksharedialog

I shared a post on Facebook set to public using the react-native-fbsdk-next library in my React Native app, but none of my friends can see it


I’m using the react-native-fbsdk-next library in my React Native app to share posts to my Facebook News Feed. The post is successfully shared, and it shows as "Public" on the News Feed. However, none of my friends can see the post, even though it appears as public on my end.

here is my code :

const shareLinkContents = {
  contentType:'photo',
  photos:[{imageUrl: image}]
};
  
ShareDialog.canShow(shareLinkContents)
  .then((canShow) => {
    if (canShow) {
      return ShareDialog.show(shareLinkContents);
    }
  })
  .then((result) => {
    if (result.isCancelled) {
      console.log('Share cancelled');
    } else {
      Object.entries(result).forEach(([key, value]) => {
        console.log(`Key: ${key}, Value: ${JSON.stringify(value)}`);
      });
      console.log('Share success with postId: ' + result);
      if (webViewRef.current)webViewRef.current.injectJavaScript(`window.location.href = '${urlToRedirect}';`);
    }
  })
  .catch((error) => {
    console.log('Share failed with error: ' + error);
  });

what did i do wrong?


Solution

  • before this you have get permission access from facebook by using below code :

    try {
          const result = await LoginManager.logInWithPermissions([
            'user_photos',
            'user_videos',
          ]);
    
          if (result.isCancelled) {
            dispatch({ type: 'notGranted' });
            console.log('Permission request cancelled');
          } else {
            const data = await AccessToken.getCurrentAccessToken();
            console.log('Permission request granted', data);
            iscliked.current = true
            dispatch({ type: 'Granted' });
          }
        } catch (error) {
          dispatch({ type: 'notGranted' });
          console.error('Error requesting permissions:', error);
        }
    

    after that you can share post publicly and all the world can see your post