2

There are so many question on the related topic but all of them ends with either complex or no solution. So here I am trying to make the things simpler so that I can get a simple answer. So please think again before marking this question duplicate, if you are thinking so.

Suppose, There is a public page, say "omgfactsonline", whose page id is "237061956027"

By the hitting the following URL, we can get very basic posts

https://www.facebook.com/feeds/page.php?id=237061956027&format=json

or

https://www.facebook.com/feeds/page.php?format=rss20&id=237061956027

As I said, the result json/xml only contains basic data (no details e.g. like count, type, comments count), which is not sufficient.

On Facebook Graph API Explorer, if i hit the path @"/237061956027/posts" with some sample token, I get the desired result.

So for the iOS app, as per Facebook developer site, the way to get the proper posts is

/* make the API call */
[FBRequestConnection startWithGraphPath:@"/237061956027/posts"
                         parameters:nil
                         HTTPMethod:@"GET"
                  completionHandler:^(
                      FBRequestConnection *connection,
                      id result,
                      NSError *error
                  ) {
                      /* handle the result */
                  }];

But problem with this code is, it needs an access token, which in an iOS app, can be only get after user authentication. As this is a general public page to get the posts from, so it does not make sense to ask user to login.

Please suggest me, how can the desired aim can be achieved.

Harshit Gupta
  • 1,200
  • 12
  • 27

2 Answers2

3

Actually, Sahil is correct but there is a way around this. Passing in the access token in your GET parameters, you can view pages that would require an App Access ID by using your AppID and AppSecret. The following should work:

//create your params
NSDictionary *params = @{@"access_token" : @"<app_id>|<app_secret"};
/* make the API call */
[FBRequestConnection startWithGraphPath:@"/237061956027/posts"
                         parameters:nil
                         HTTPMethod:@"GET"
                  completionHandler:^(
                      FBRequestConnection *connection,
                      id result,
                      NSError *error
                  ) {
                      /* handle the result */
                  }];

From the Facebook API https://developers.facebook.com/docs/facebook-login/access-tokens#apptokens

AndrewSmiley
  • 1,933
  • 20
  • 32
1

According to the Page Documentation, to read a page's wall-

An app or user access token is needed to view fields from fully public pages.
A user access token is needed to view fields from restricted pages that this person is able to view (such as those restrict to certain demographics like location or age, or those only viewable by Page admins).
A page access token can also be used to view those restricted fields.

So, to get the posts from a public page without logging on the user, you can create an app and use the app access token(app_id|app_secret) (that never expires).

If you still get the empty result that means the posts are not public. For eg:

(But please note its not safe to expose the app access token to the client side as this is kinda password to your app.)

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90