Как хранить информацию о публичном профиле API FB graph API - PullRequest
0 голосов
/ 05 октября 2019

У меня возникают трудности с сохранением ответа API графика Facebook для деталей профиля (имя, изображение профиля электронной почты и идентификатор) в переменные, которые я позже могу создать в объекте. Я получаю эту ошибку

Value of type 'Any?' has no member 'dictionaryValue'

И вот мой метод

func getUseProfile() {
    let graphRequest : GraphRequest = GraphRequest(graphPath: "/me", parameters: ["fields":"id, email, name, picture.width(480).height(480)"], httpMethod: .get)

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

        if error != nil {
            print("Error took place: \(String(describing: error))")
        }
        else {

            print("Print entire fetched result: \(String(describing: result))")
            print("Print id: \(String(describing: "id"))")

            if let responseDictionary = result.dictionaryValue {
                let fbEmail = responseDictionary["email"] as? String
                print(fbEmail)
                let fbName = responseDictionary["name"] as? String
                print(fbName)
                let fbId = responseDictionary["id"] as? String
                print(fbId)
                if let picture = responseDictionary["picture"] as? NSDictionary {
                    if let data = picture["data"] as? NSDictionary{
                        if let profilePicture = data["url"] as? String {
                            print(profilePicture)
                }}}}
        }
    })
    }

Типичный ответ API графика:

 ({
email = "test@gmail.com";
id = 2624827091891056;
name = "Test Test";
picture =     {
    data =         {
        height = 480;
        "is_silhouette" = 0;
        url = "https://platform-lookaside.fbsbx.com/platform/profilepic/? 
 asid=2624827091891056&height=480&width=480&ext=1572756671&hash=AeQLcrXR_f-mejoi";
        width = 480;
    };
 };
 })
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...