Facebook 图 API link 参数返回 nil

Facebook graph API link parameter returning nil

我正在尝试存储已登录的 Facebook 用户的 Facebook 用户名(例如 www.facebook.com/james.dean01),以便通过 Messenger(类似于 How to open Facebook Messenger and direct to someone?). I am configuring a button which will send a user directly to someones messenger chat but to do so I need their username/facebook URL. I am attempting to use the "link" property (Facebook graph API: https://developers.facebook.com/docs/graph-api/reference/user) 以获得可用于此目的的用户配置文件的 link,只有 link 属性(已打印)returns 为零。我不确定我做错了什么。目的是每次用户登录时都会读取数据并更新数据库。下面是代码。

如有任何帮助,我们将不胜感激!

import FacebookCore

class FacebookService {
static let instance = FacebookService()

let params = ["fields": "email, first_name, last_name, link, picture, name"]

func recordUserData() {
    let graphRequest = GraphRequest(graphPath: "me", parameters: params)
    graphRequest.start {
        (urlResponse, requestResult) in

        switch requestResult {
        case .failed(let error):
            print("error in graph request:", error)
            break
        case .success(let graphResponse):
            if let responseDictionary = graphResponse.dictionaryValue {
                print(responseDictionary)

                let link = responseDictionary["link"] as? String
                let email = responseDictionary["email"] as? String
                let fbId = responseDictionary["id"] as? String
                let name = responseDictionary["name"] as? String

                let picture = responseDictionary["picture"] as? NSDictionary
                let data = picture!["data"] as? NSDictionary
                let url = data!["url"] as? String

                print("Link: \(link)")
                print(url)

            }
        }
    }
  }
}

您需要请求必要的许可,https://developers.facebook.com/docs/facebook-login/permissions#reference-user_link

并且此权限的使用需要通过 Facebook 审核,然后才能在您的实时应用中使用它。

但不确定您是否会通过审核,因为您将要做的基本上就是它所说的不允许的用例:

Attempt to programmatically determine someone's Facebook username or canonical User ID.

所以不能保证 Facebook 会批准这个;您只能尝试提交它以供审核,看看您会得到什么反馈。