2014-03-04 82 views

回答

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" 
} 
+0

你能否给我从facebook获取封面图片的网址? – Surfer

+0

这个返回错误'(#100)类型必须是以下值之一:小,普通,大,广场' – Surfer

+0

是封面图片或个人资料图片的错误?因为类型值已经是“大”(即请求的值之一)! – MuhammadBassio

0

你可以得到大的图像资料图片作为

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

类型参数支持

enum{square,small,normal,large} 
0

这里是你必须获得进入到Facebook账户的用户的迅速3.

  1. 答案在他或她的设备中,使用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) 
    
         } 
        } 
    } 
    
  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"))") 
        } 
    
    }) 
    
    } 
    

以上是用于获取用户的图像轮廓和代码的信息,如电子邮件地址,性别和生日。

这是像tinder这样的应用程序获取您的数据,并不要求用户登录到Facebook帐户,如果用户有他的Facebook帐户链接到他或她的iPhone。

我希望这可以帮助别人,开心编码:)。

相关问题