-1

Hey i'm trying to get public post from specific page but i don't want user to login.
and as stated in this Post that i can use my app access token for this but my problem is how i can add my app token to graph request because AccessToken.getCurrentAccessToken()
return null and that obvious because the user is not authenticated
so what is the proper way to set the app access Token

this is my code

  new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            "/Page_id/posts",
            null,
            HttpMethod.GET,
            new GraphRequest.Callback() {
                public void onCompleted(GraphResponse response) {
        /* handle the result */
                  System.out.println(response.toString());
                }
            }
    ).executeAsync();
Community
  • 1
  • 1
Antwan
  • 3,837
  • 9
  • 41
  • 62
  • You should not use your app access token in client-side code. – CBroe Jun 29 '15 at 07:42
  • Thanks man but how could i achieve this i need to get just public post and i dont need to login – Antwan Jun 29 '15 at 07:44
  • Then you should do it server-side (because that is the only save place to use an app access token). If you don’t have a server-side component to your app – then make users login to your app before they use it, so you can use their user access token. – CBroe Jun 29 '15 at 07:46
  • but if we compare this to opening facebook page from browser can see the page public post so why i can't do same this in mobile side ? sorry @CBroe but i just need to understand this more – Antwan Jun 29 '15 at 07:51
  • and also in IOS SDK we can set the Access Token as fixed String and it works perfectly – Antwan Jun 29 '15 at 08:09
  • _“so why i can't do same this in mobile side ?”_ – because viewing content directly on Facebook, and retrieving content via API are two different things. Facebook has _decided_ that such API requests need to use an access token now, period. And that you _can_ embed your app access token in iOS code, doesn’t mean that you _should_ do it. See https://developers.facebook.com/docs/facebook-login/access-tokens#apptokens: _“Again, for security, app access token should __never__ be hard-coded into client-side code.”_ – CBroe Jun 29 '15 at 09:08
  • ok Thanks @CBroe could u provide ur comment as an answer it could help the others – Antwan Jun 29 '15 at 09:10
  • i also took a look on this question and even if i the admin of the page they said that this action no more available after 30 may http://stackoverflow.com/questions/8231877/facebook-access-token-for-pages/12308883#12308883 – Antwan Jun 29 '15 at 09:33
  • I can’t see what you are referring to there. That specific answer you linked to does not mention anything in that regard, and in the rest of the discussion I don’t see anything pertaining to this issue either. – CBroe Jun 29 '15 at 10:13

1 Answers1

1

If you decide to use your app access token to request those posts, then you should do it server-side – because that is the only save place to use an app access token.

If you don’t have a server-side component to your app, and want to fetch the posts client-side – then make users login to your app before they use it, so you can use their user access token.

CBroe
  • 91,630
  • 14
  • 92
  • 150