将 Facebook 的提要列表与图形 api 集成时的问题

Posted

技术标签:

【中文标题】将 Facebook 的提要列表与图形 api 集成时的问题【英文标题】:issues while integrating feed list of face book with graph api 【发布时间】:2018-07-25 05:38:38 【问题描述】:

我想从 facebook 的特定应用程序获取提要列表,我目前正在使用图形 api,让我展示我的代码以获得更好的解释

代码::

  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=feedmessage,full_picture,id,application,likesname,pic_crop,commentsmessage,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")!

            
        )
    

但是我没有得到响应,而是在 Graph Api explorer "me/?fields=feedmessage,full_picture,id,application,likesname,pic_crop,cmetsmessage,from,created_time,created_time “我正在添加这条线,然后它的工作正常,但在整合时我没有得到回应

如果我将“我/帖子”作为 graphPath 传递,那么我会得到如下响应

响应::


  "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"
  

但我想点赞评论所有数据,但我没有得到回复

有人帮帮我吗?

【问题讨论】:

用 Facebook 链接检查登录:- ***.com/a/50559619/5146460 是的,我只收到姓名电子邮件,但我希望喜欢 cmets 计数,正如我在传递“me/?fields=feedmessage,full_picture,id, application,likesname,pic_crop,cmetsmessage,from,created_time,created_time”这个graphPath然后它的工作但是当我实现然后没有得到响应 【参考方案1】:

试试这个代码

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)
            
        )
    

【讨论】:

以上是关于将 Facebook 的提要列表与图形 api 集成时的问题的主要内容,如果未能解决你的问题,请参考以下文章

Facebook 图形 API 用于获取带有评论数和点赞数的 Facebook 订阅源

升级图 API 2.0 后从 Facebook 读取新闻提要失败

如何使用图形 API 在 iphone 中喜欢 facebook 社区

Facebook Graph API 与喜欢的帖子不同

无法通过 Graph API 将提要发布到 Facebook 页面

通过图形 API 获取 facebook 好友的完整列表