How to view posts from a facebook page?

Asked

Viewed 278 times

0

I want to view posts from a facebook fanpage in an app.

I’ve been doing some research and some people helped me and told me to use the Facebook API. Pis well, I am using, but, as facebook does not help anyone, I come here to ask for your help.

I’m using the code below, but from there how do I make the posts appear?

PS: I already have the access token but I don’t know how to use it.

new GraphRequest(
        AccessToken.getCurrentAccessToken(),
        "/251217778341818/feed",
        null,
        HttpMethod.GET,
        new GraphRequest.Callback() {
            @Override
            public void onCompleted(GraphResponse graphResponse) {
                try {
                    String titulo = graphResponse.getJSONObject().getString("");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
).executeAsync();
  • Carlos, you had said that "I will import 'Httpmethod.GET' it from the bug". What is the mistake? Better describes your doubt that hence the answer becomes simpler and objective.

  • Able to solve Bruno, I don’t know how else I got kkkkkk I think it was only the version of the api changed from 4.0.0 to 4.1.0

  • Cool Carlos, thanks a lot.

  • but I still don’t know how to take the information and display the posts, and the access token I already have but I can’t set @Brunocésar

1 answer

1

Facebook provides API for you to access this information.

In your case, to list the feed of a fan page, there is the service /page/feed in Graph API. In this case everything in the feed is listed, including status updates and posts from other users.

See the variance /page/posts to have only the posts posted by the page.

Removing from the reference documentation, a javascript example would be:

FB.api(
    "/{page-id}/feed",
    function (response) {
      if (response && !response.error) {
        // faça seu trabalho aqui
      }
    }
);

And this other on android SDK:

new Request(
    session,
    "/{page-id}/feed",
    null,
    HttpMethod.GET,
    new Request.Callback() {
        public void onCompleted(Response response) {
            // faça seu trabalho aqui
        }
    }
).executeAsync();

In the reference documentation you can find all the information needed to use the API, including how to get the {page-id}.

How did you quote the tags and , see the Sdks javascript and android

  • I have tried but this Callback() method is not recognized.

  • @Carloseduardosilva which version of Android SDK you tried to?

  • compileSdkVersion 22 buildToolsVersion "22.0.1"

  • @Carloseduardosilva the SDK version of facebook. Probably using the 4, due to android version. For the version 4 from the facebook SDK, use GraphRequest in place of Request.

  • @Carloseduardosilva the session is the AccessToken

  • ok!! but then when I will import 'Httpmethod.GET' it from error..

  • @Carloseduardosilva updates your question (or create another one) with more details than you’ve tried, errors, etc., which update the question.

  • ready, updated the question

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.