Swift: the result ["data"] always returns nil while I get data from Facebook using FBSDK 4.x

I am trying to get a photo of albums from facebook using FBSDK 4.x and I get the result as json. Then I try to access its properties, how is this result ? ["Data"] ', and it always returns nil . See below code:

    func fetchAlbum(){
    print(FBSDKAccessToken.currentAccessToken())
    let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me?fields=albums", parameters: nil);
    graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in
        if let gotError = error{
            println(gotError.description);
        }
        else{
            print("fetched data: \(result)")            
            if let graphData = result["data"] as? [FBSDKShareOpenGraphObject]{ 
                var albums:[AlbumModel] =  [AlbumModel]();
                for obj:FBSDKShareOpenGraphObject in graphData {
                let desc = obj.description;
                print(desc);
                let name = obj.valueForKey("name") as! String;
                print(name);
                if(name == "ETC"){
                    let test="";
                }
                let id = obj.valueForKey("id") as! String;
                var cover = "";
                if let existsCoverPhoto : AnyObject = obj.valueForKey("cover_photo"){
                    let coverLink = existsCoverPhoto as! String;
                    cover = "/\(coverLink)/photos";
                }
                //print(coverLink);
                let link = "/\(id)/photos";
                let model = AlbumModel(name: name, link: link, cover:cover);
                albums.append(model);
                }
            NSNotificationCenter.defaultCenter().postNotificationName("albumNotification", object: nil, userInfo: ["data":albums]);

                }else{
                    print("--------------------------")
            } 
        }
    })
}

Can anyone help me in this code above?

+4
source share

All Articles