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 908 forks source link

How to post a picture to a facebook group/page? #774

Closed hotmailbelike closed 3 years ago

hotmailbelike commented 4 years ago

I am trying to control groups and/or pages by my own react native app using the facebook graph api. I was able to successfully make text posts to groups but unable to do it for photos. However, through Facebook's Graph api tool I was able to do it, here is a screenshot:

image

But when I try it through react native using axios it does not work, here is my code:

axios
      .post('https://graph.facebook.com/689308475184766/photos', {
        url: 'https://images.unsplash.com/photo-1506329638946-064b92d6f3c1?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80',
        caption: 'hardcode',
        accessToken: FBtoken,
      })
      .then(res => {
        res = res.data;
        alert('Made Photo Post to Prochar Group!');
      })
      .catch(error => {
        console.log('postPhoto -> error', error);
        setError(error);
      });

This is the error I get: [Error: Request failed with status code 400]

Please Note: using this same axios method I am able to make a text post to the group like this:

axios
      .post('https://graph.facebook.com/689308475184766/feed', {
        message: 'Hello',
        access_token: FBtoken,
      })
      .then(res => {
        res = res.data;

        alert('Posted to Prochar group!');
      })
      .catch(error => {
        console.log('handleSubmit -> error', error);
        setError(error);
      });