facebookarchive / react-native-fbsdk

A React Native wrapper around the Facebook SDKs for Android and iOS. Provides access to Facebook login, sharing, graph requests, app events etc.
https://developers.facebook.com/docs/react-native
Other
2.99k stars 907 forks source link

Getting API_ERROR when trying to use the ShareDialog #554

Closed ondrej-merkun closed 5 years ago

ondrej-merkun commented 5 years ago

🐛 Bug Report

I'm getting error API_ERROR: API_ERROR when trying to open a ShareDialog.

To Reproduce

Just use the ShareDialog example from the Facebook SDK documentation in your code/project and run it on a device.

Expected Behavior

I expected to either see and alert with the text "Share operation was cancelled" or "Share was successful with postID: ".

Code Example

const App = () => {
  const [state, setState] = useState({
    shareLinkContent: {
      contentType: 'link',
      contentUrl: 'https://facebook.com',
      contentDescription: 'Facebook sharing should be easy :(',
    },
  });

  const shareLinkWithShareDialog = () => {
    console.log(state.shareLinkContent);
    ShareDialog.canShow(state.shareLinkContent)
      .then(canShow => {
        if (canShow) {
          return ShareDialog.show(state.shareLinkContent);
        }
      })
      .then(result => {
        if (result.isCancelled) {
          alert('Share operation was cancelled');
        } else {
          alert('Share was successful with postId: ' + result.postId);
        }
      })
      .catch(error => {
        alert('Error: ' + error.message);
      });
  };

  useEffect(() => {
    shareLinkWithShareDialog();
  }, []);

  return <View />;
};

Environment

I've only tried this on an Android device.

System: OS: macOS 10.14.6 CPU: (4) x64 Intel(R) Core(TM) i5-5350U CPU @ 1.80GHz Memory: 32.28 MB / 8.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 11.10.1 - ~/.nvm/versions/node/v11.10.1/bin/node Yarn: 1.15.2 - /usr/local/bin/yarn npm: 6.9.0 - ~/.nvm/versions/node/v11.10.1/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2 IDEs: Android Studio: 3.4 AI-183.5429.30.34.5452501 Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild npmPackages: react: 16.8.3 => 16.8.3 react-native: 0.59.9 => 0.59.9 npmGlobalPackages: create-react-native-app: 2.0.2 react-native-cli: 2.0.1

ondrej-merkun commented 5 years ago

SOLVED by using a valid App ID in android/app/src/main/res/values/strings.xml