我已经使用了SLRequest
获取个人资料信息,并且我遵循了在 iOS6 中获取用户个人资料图片?获取个人资料图像。但它返回50x50
图像尺寸。我需要大尺寸的个人资料图片。谁能给我一些想法来做到这一点SLRequest
?
问问题
1190 次
3 回答
1
使用以下 URL 获取大图:
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"
}
于 2014-03-04T09:06:36.517 回答
0
您可以获得个人资料图片的大图为
[NSURL URLWithString:@"https://graph.facebook.com/me/picture?type=large"];
类型参数支持
enum{square,small,normal,large}
于 2014-03-04T09:53:47.477 回答
0
这是swift 3的答案。
您必须在他或她的设备中访问用户的 facebook 帐户,这使用 accountStore API:
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) } } }
收到响应后,用户就授予了对该帐户的访问权限。您可以使用 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"))") } }) }
以上是获取用户个人资料图像和信息(如电子邮件、性别和生日)的代码。
这是 tinder 等应用程序获取您的数据的方式,如果用户的 facebook 帐户与他或她的 iphone 相关联,则不会要求用户登录 facebook 帐户。
我希望这对某人有所帮助,编码愉快:)。
于 2017-08-06T01:45:19.670 回答