简体   繁体   中英

issues while integrating feed list of face book with graph api

I want to get feed list from particular app of facebook and i am currently using graph api let me show my code for better explanation

Code::

  func PostList(){
        var Requset : FBSDKGraphRequest

        print("\(FBSDKAccessToken.current())")

        let acessToken = String(format:"%@", FBSDKAccessToken.current().tokenString) as String

        print("\(acessToken)")

        let parameters1 = ["access_token":FBSDKAccessToken.current().tokenString]


        Requset  = FBSDKGraphRequest(graphPath:"me/?fields=feed{message,full_picture,id,application,likes{name,pic_crop},comments{message,from,created_time},created_time}", parameters:parameters1, httpMethod:"GET")

        Requset.start(completionHandler: { (connection, result, error) -> Void in

            //MBProgressHUD.hideHUDForView(appDelegate.window, animated: true)

            if ((error) != nil)
            {
                print("Error: \(error)")
            }
            else
            {
                print("fetched user: \(result)")

                //var dataDict: AnyObject = (result! as AnyObject).object(forKey: "data")!

            }
        })
    }

but from this i am not getting response but in Graph Api explorer "me/?fields=feed{message,full_picture,id,application,likes{name,pic_crop},comments{message,from,created_time},created_time}" i am adding this line then its work fine but while integrating i am not getting response

if i pass "me/posts" as graphPath then i am getting response like below

Response::

{
  "data": [
    {
      "message": "Test Post",
      "created_time": "2018-07-12T11:46:58+0000",
      "id": "103361910512644_196181887897312"
    },
    {
      "message": "Fgfhjjhh",
      "created_time": "2018-07-11T11:26:35+0000",
      "id": "103361910512644_195184807997020"
    },
    {
      "message": "Test",
      "created_time": "2018-07-11T11:00:57+0000",
      "id": "103361910512644_195166977998803"
    },
    {
      "message": "fhchfhgfhfghg",
      "created_time": "2018-07-10T05:55:18+0000",
      "id": "103361910512644_193906868124814"
    },
    {
      "message": "Test",
      "created_time": "2018-07-10T05:11:00+0000",
      "id": "103361910512644_193879061460928"
    },
    {
      "created_time": "2018-07-09T11:04:42+0000",
      "id": "103361910512644_193122468203254"
    },
    {
      "created_time": "2018-07-09T11:04:13+0000",
      "id": "103361910512644_193122148203286"
    },
    {
      "created_time": "2018-07-09T11:03:53+0000",
      "id": "103361910512644_193121878203313"
    },
    {
      "created_time": "2018-07-09T11:03:28+0000",
      "id": "103361910512644_193121571536677"
    },
    {
      "created_time": "2018-07-06T08:44:58+0000",
      "id": "103361910512644_190085968506904"
    },
    {
      "created_time": "2018-07-06T08:44:42+0000",
      "id": "103361910512644_190085751840259"
    },
    {
      "message": "Test test ..hfjdhdududhd",
      "created_time": "2018-07-03T11:05:28+0000",
      "id": "103361910512644_187249475457220"
    },
    {
      "message": "Test Post From Mode Share App.",
      "created_time": "2018-07-03T09:46:25+0000",
      "id": "103361910512644_187196988795802"
    },
    {
      "message": "Test Post From Web.",
      "created_time": "2018-07-02T11:25:33+0000",
      "id": "103361910512644_186233918892109"
    },
    {
      "message": "Test Post From App.",
      "created_time": "2018-07-02T11:24:43+0000",
      "id": "103361910512644_186233275558840"
    }
  ],
  "paging": {
    "previous": "https://graph.facebook.com/v3.0/103361910512644/posts?format=json&since=1531396018&access_token=EAAC5SyZBtEogBAN9lib8o4ZA9M6ZCGIINBFAJtttfWysfZA5IvMPZAm6XsR9YhMMTLwTb9ScejLgey5gJiPsNsfGL4kk0ObIWdpTtjrJZAvqAmGR82xdTva6dlGeSucJol2WMVvjyjpajvVZCde4HEk6EbFjzczzCmtF31jqnsMrrZBKyZCCJ7ncaNjGhSC4RfMAxNSWyqwBMerdTJyzCpoFZA&limit=25&__paging_token=enc_AdA4E14ICu5l7HjzFFe6w188bKHbs4UPmOwoYRjmEdZBECzR4IYVdR7ZANBAYWlXT9ZCM8MYNaXMPbLLcByDWnZCohogKburL9Ardw9KOLz6Bi61HQZDZD&__previous=1",
    "next": "https://graph.facebook.com/v3.0/103361910512644/posts?format=json&access_token=EAAC5SyZBtEogBAN9lib8o4ZA9M6ZCGIINBFAJtttfWysfZA5IvMPZAm6XsR9YhMMTLwTb9ScejLgey5gJiPsNsfGL4kk0ObIWdpTtjrJZAvqAmGR82xdTva6dlGeSucJol2WMVvjyjpajvVZCde4HEk6EbFjzczzCmtF31jqnsMrrZBKyZCCJ7ncaNjGhSC4RfMAxNSWyqwBMerdTJyzCpoFZA&limit=25&until=1530530683&__paging_token=enc_AdDQAFGJpwBvzZAnvmFIdJ4w5mCemiG8rcZCMslwNWjOSwtxqUpA7cZCzAVjJUwZCA2se9tEuOotiSxTDGT6ddnWvfGnRCMxC90ublTHqFZC6F34qrQZDZD"
  }
}

but i want like count comment all data but i am not getting response

Any One help me?

Try this code

if FBSDKAccessToken.current() != nil{
        let graphRequest = FBSDKGraphRequest(graphPath: "/me", parameters: ["fields": "email, name, friends"], httpMethod: "GET")
        let connection = FBSDKGraphRequestConnection()

        connection.add(graphRequest, completionHandler: { (connection, result, error) -> Void in
            if error == nil
            {
                print(result)
            }
        })
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM