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

前端 未结 10 1280
天涯浪人
天涯浪人 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:29

    With Facebook SDK 4.0, you can use:

    Swift:

        let pictureRequest = FBSDKGraphRequest(graphPath: "me/picture?type=large&redirect=false", parameters: nil)
        pictureRequest.startWithCompletionHandler({
            (connection, result, error: NSError!) -> Void in
            if error == nil {
                println("\(result)")
            } else {
                println("\(error)")
            }
        })
    

    Objective-C:

    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                      initWithGraphPath:[NSString stringWithFormat:@"me/picture?type=large&redirect=false"]
                                      parameters:nil
                                      HTTPMethod:@"GET"];
        [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                              id result,
                                              NSError *error) {
        if (!error){
           NSLog(@"result: %@",result);}
        else {
           NSLog(@"result: %@",[error description]);
         }}];
    

提交回复
热议问题