如何使用SLRequest获取大尺寸的Facebook个人资料图片?

时间:2014-03-04 08:58:36

标签: ios iphone objective-c facebook slrequest

我已使用SLRequest获取个人资料信息,然后我按照Getting user profile picture in iOS6?获取个人资料图片。但它返回50x50图像尺寸。我需要大尺寸的个人资料图片。任何人都可以使用SLRequest给我一些想法吗?

3 个答案:

答案 0 :(得分:1)

使用以下网址获取大图片:

https://graph.facebook.com/fb_user_id/picture?type=large

对于封面图片,请使用以下内容:

http://graph.facebook.com/fb_user_id?fields=cover

这将返回:

{
  "cover": {
    "id": "XXX", 
    "source": "cover_image_url", 
    "offset_y": 66
  }, 
  "id": "XXXXXX"
}

答案 1 :(得分:0)

您可以将个人资料图片的大图片视为

[NSURL URLWithString:@"https://graph.facebook.com/me/picture?type=large"];

type参数支持

enum{square,small,normal,large}

答案 2 :(得分:0)

以下是swift 3的答案。

  1. 您必须使用accountStore API访问其设备中用户的Facebook帐户:

      func accessFacebookAccount(onCompletion: @escaping(_ tokenCredential: 
      String, 
       _ facebookAccount: ACAccount) -> Void, onError: @escaping (_ 
     errorMessage:  String?) -> Void) {
    
    
            let accountStore = ACAccountStore()
            let facebookAccountType = accountStore.accountType(withAccountTypeIdentifier: ACAccountTypeIdentifierFacebook)
    
            let options = [
            "ACFacebookAppIdKey" : "529210493918001",
            "ACFacebookPermissionsKey" : ["email","public_profile"],
            "ACFacebookAudienceKey" : ACFacebookAudienceOnlyMe] as [String : Any]
    
        accountStore.requestAccessToAccounts(with: facebookAccountType, options: options) { (granted, error) in
            if granted {
    
    
                let fbAccount = accountStore.accounts(with: facebookAccountType).last as? ACAccount
    
                let credential = fbAccount?.credential
    
    
                let token = credential?.oauthToken
                onCompletion(token!, fbAccount!)
    
            } else {
                let error = "Access to Facebook was not granted."
                onError(error)
    
            }
        }
    }
    
  2. 获得响应后,用户就可以访问该帐户。您可以使用ACAccount对象并通过SLRequest访问Facebook信息:

    func getFacebookInfoViaAccounts (_ fbAccount: ACAccount) {
    
    
    let myURL = URL(string: "https://graph.facebook.com/me")
    
    let request = SLRequest.init(forServiceType: SLServiceTypeFacebook, requestMethod: .GET, url: myURL, parameters: ["fields":"email, first_name, last_name,birthday, gender"])
    
    request?.account = fbAccount
    
    request?.perform(handler: { (dataResponse, urlResponse, error) in
    
        if error == nil {
    
            let json = try? JSONSerialization.jsonObject(with: dataResponse!, options: [ JSONSerialization.ReadingOptions.allowFragments])
    
            if let dict = json as? [String: Any] {
    
                print("My data \(dict)")
            }
        }
    
    })
    
    let myPhotoURl = URL(string: "https://graph.facebook.com/me/picture")
    
    let requestPhoto = SLRequest.init(forServiceType: SLServiceTypeFacebook, requestMethod: .GET, url: myPhotoURl, parameters: ["type":"large"])
    
    requestPhoto?.account = fbAccount
    
    requestPhoto?.perform(handler: { (dataResponse, urlResponse, error) in
    
        if error == nil {
    
            print("URL DE LA PHOTO \(urlResponse?.value(forKey: "URL"))")
        }
    
    })
    
    }
    
  3. 以上是获取用户个人资料图片和信息的代码,如电子邮件,性别和生日。

    如果用户将自己的Facebook帐户链接到他或她的iPhone,这就是tinder之类的应用程序获取您的数据并且不要求用户登录Facebook帐户的方式。

    我希望这有助于某人,快乐编码:)。

相关问题