Facebook iOS SDK and swift: how get user's profile picture

前端 未结 10 1253
天涯浪人
天涯浪人 2021-01-31 03:51

i have integrated Facebook sdk in Xcode 6 (with swift). During the login i request the public_profile permission:

FBSession.openActiveSessionWithReadPermissions(         


        
10条回答
  •  一整个雨季
    2021-01-31 04:45

    For swift this is the simple way for get the url of the photo with and specific size:

        let params: [NSObject : AnyObject] = ["redirect": false, "height": 800, "width": 800, "type": "large"]
        let pictureRequest = FBSDKGraphRequest(graphPath: "me/picture", parameters: params, HTTPMethod: "GET")
        pictureRequest.startWithCompletionHandler({
            (connection, result, error: NSError!) -> Void in
            if error == nil {
                print("\(result)")
    
    
               let dictionary = result as? NSDictionary
               let data = dictionary?.objectForKey("data")
               let urlPic = (data?.objectForKey("url"))! as! String
               print(urlPic)
    
    
    
            } else {
                print("\(error)")
            }
        })
    
    }
    

提交回复
热议问题