Search code examples
iosswift3fbsdkfbsdksharekit

how to fetch fb pages list or their place id using FBSDK in swift 3


I am new in swift so please help me regarding FBSDK. Fetching FB pages of a fb account. I need it to post on fb page directly from my app.


Solution

  • Hi i found answer for this myself.. here is my answer .. hope it will help someone :

    let graphRequest
     = FBSDKGraphRequest(graphPath: "/me/accounts?fields=access_token", parameters: ["access_token":FBSDKAccessToken.current().tokenString])
    graphRequest.start(completionHandler: { (connection, result, error)-> Void in
                if ((error) != nil)
                {
                    print("Error: \(error)")
                }
                else
                {
    
                    let array = ((result as! NSDictionary).value(forKey: "data") as! NSArray)
    
                    for tokens in array{
                        let tkn = ((tokens as! NSDictionary).value(forKey: "access_token")) as! String
                        let id = ((tokens as! NSDictionary).value(forKey: "id")) as! String
                        let obj = AccessToken()  //NSOBject class containing accessToken and id variables...
                        obj.access_token=tkn
                        obj.id=id
                        self.accessTokenArray.append(obj)  // global var to store AccessToken type array
                    }
    
                }
            })