Search code examples
iosswiftfacebook-graph-apifacebook-sdk-4.0

How to get facebook feed with images and videos along with text?


I want to fetch logged user feeds within ios app, I have try with graph api that, graph api returns the data, its fine. But when I have cross check the data to the actual facebook feed on facebook user page there are some problems found:

  1. If post has text only than text coming on message key, along with post id,
  2. If post has text with image/video only text coming on message key
  3. And if post has only image/video than message key not coming.

I know message key is only for description/text but images? Is there any way to get the feed with whole content just same as appeared on facebook.

I have try below code:

For Login

FBSDKLoginManager().logOut()
    FBSDKLoginManager().logIn(withReadPermissions: ["email", "public_profile", "user_posts"], from: self) { (result, error) in
        if error != nil {
            print("failed to start graph request: \(String(describing: error))")
            return
        }
       // self.getPosts()//old
        self.getFBPost()
    }

For getFBPost

 func getFBPost() {
    FBSDKGraphRequest(graphPath: "/me/feed", parameters: nil)?.start(completionHandler: { (fbConnectionErr, result, error) in
       // print(fbConnectionErr)
        print(result)
        //print(error)
    })
}

Coming response like this:

{
  "data": [
    {
      "message": "https://medium.com/frame-io-engineering/huge-images-small-phone-15414b30d39e",
      "created_time": "2018-12-03T13:59:01+0000",
      "id": "68288174406_653966194"
    },
    {
      "created_time": "2018-12-01T13:43:02+0000",
      "id": "68288174406_6528518443724"
    },
    {
      "message": "I love my Mom",
      "created_time": "2018-11-30T13:27:38+0000",
      "id": "68288174406_652289420323"
    }

}

as you can see the second post has only id and created time, while we check this on facebook page this the post with image, and third post has video but only text coming from graph api

Please guide whats wrong I did? Or What should I do to getting whole feed data in json formate just same as appeared on facebook?


Solution

  • You are not asking for any fields in the API call, so you only get default ones. It is called "Declarative Fields" (/me?fields=message,created_time,...) and came with v2.4: