2
votes

since yesterday i try to post a status with image (or not) with a facebook page with facebook graph api.

client is connected with this scope :

email, public_profile, manage_pages, user_posts, publish_actions, publish_pages

i call this function

    postPicture = () => {
        FB.api("/231713458314438/feed",
                "POST", 
                {
                    "link": "http://ichef-1.bbci.co.uk/news/660/cpsprodpb/17A21/production/_85310869_85310700.jpg",
                    "message": "test"
                },
                function (response) {
                    console.log(response)
                }
        );
    }

publication is published but with my personnal account ON page and not in Admin with page.

So have you an idea to how published a status with page?

2

2 Answers

1
votes

From the documentation here : https://developers.facebook.com/docs/graph-api/overview/

You would also need to pass the access_token generated for the logged in admin as a paremeter request:

postPicture = () => {
    FB.api("/231713458314438/feed",
            "POST", 
            {
                "link": "http://ichef-1.bbci.co.uk/news/660/cpsprodpb/17A21/production/_85310869_85310700.jpg",
                "message": "test",
                "access_token": {your-access-token}
            },
            function (response) {
                console.log(response)
            }
    );
}
0
votes
  1. Get User access token from Facebook Portal

    • https://developers.facebook.com/tools/explorer

      Select "Facebook App": Your App

      Select "User or Page": User Token (Get User Access Token)

      Select Permission: "pages_manage_posts"

      Click copy Access Token:

      • => Short-Lived User Access Token: SLUATOKEN
  2. Get Long-Lived User Access Token

  3. Get User ID

    • User ID is required in Step 4

      curl -i -X GET "https://graph.facebook.com/v10.0/me?fields=id%2Cname&access_token={Long-Live User Access Token}"
      

      => CURL:

      curl -i -X GET "https://graph.facebook.com/v10.0/me?fields=id%2Cname&access_token=LONGLIVEDUATOKEN"
      
      • => Got User ID: YOURFBID
  4. Get Long-Lived Page token

  5. Post Status

  6. Check Token Expired Time