2014-03-04 117 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。

我希望這可以幫助別人,開心編碼:)。

相關問題