如何檢測鏈接上的默認頭像是這樣的:https://graph.facebook.com/'.$id.'/picture?type=large
? 它是從特殊準備的配置文件中獲得化身(男性/女性)的唯一方法,然後通過比較md5()?如何檢測Facebook上的默認頭像?
很難相信這是唯一的方法。
如何檢測鏈接上的默認頭像是這樣的:https://graph.facebook.com/'.$id.'/picture?type=large
? 它是從特殊準備的配置文件中獲得化身(男性/女性)的唯一方法,然後通過比較md5()?如何檢測Facebook上的默認頭像?
很難相信這是唯一的方法。
沒有可以調用的API來判斷它們是否使用默認的照片。而不是下載整個圖像和檢查MD5的,你可以發出HTTP HEAD請求到個人資料網址,並期待在Location
頭,看看URL是已知的默認配置文件圖像之一:
男:https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v2/yL/r/HsTZSDw4avx.gif
女(達斯維德):https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v2/yp/r/yDnr5YfbJCH.gif
這些網址可能會改變我猜想,所以可以在默認的照片,但我還沒有看到任何一種情況下發生的I C記住。
可以使用redirect=false
參數:
https://graph.facebook.com/naitik/picture?redirect=false
那麼Facebook的性反應是json
和包含此數據:
{
"data": {
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/157337_5526183_369516251_q.jpg",
"is_silhouette": false
}
}
可以使用is_silhouette
選項來檢測,如果照片是默認一。
你可以讀到更多在:https://developers.facebook.com/docs/reference/api/using-pictures/
如果你已經開始對圖形API的調用來得到像頭像的用戶數據,只包括在fields PARAM picture
當您第一次調用圖形API ,那麼響應將包括is_silhouette
偏移量,如果它設置爲true,則用戶具有默認頭像。
請求:
https://graph.facebook.com/v2.7/me?access_token=[token]&fields=name,picture
響應:
{
"id": "100103095474350",
"name": "John Smith",
"picture": {
"data": {
"is_silhouette": true,
"url": "https://scontent.xx.fbcdn.net/v/...jpg"
}
}
}
使用Facebook SDK適用於iOS(SWIFT 4):
class FacebookSignIn {
enum Error: Swift.Error {
case unableToInitializeGraphRequest
case unexpectedGraphResponse
}
func profileImageURL(size: CGSize, completion: @escaping Result<URL?>.Completion) {
guard let userID = FBSDKAccessToken.current()?.userID else {
completion(.failure(Error.unableToInitializeGraphRequest))
return
}
let params: [String: Any] = ["redirect": 0,
"type": size.width == size.height ? "square" : "normal",
"height": Int(size.height),
"width": Int(size.width),
"fields": "is_silhouette, url"]
guard let request = FBSDKGraphRequest(graphPath: "/\(userID)/picture", parameters: params) else {
completion(.failure(Error.unableToInitializeGraphRequest))
return
}
_ = request.start { _, result, error in
if let e = error {
completion(.failure(e))
} else if let result = result as? [String: Any], let data = result["data"] as? [String: Any] {
if let isSilhouette = data["is_silhouette"] as? Bool, let urlString = data["url"] as? String {
if isSilhouette {
completion(.success(nil))
} else {
if let url = URL(string: urlString) {
completion(.success(url))
} else {
completion(.failure(Error.unexpectedGraphResponse))
}
}
} else {
completion(.failure(Error.unexpectedGraphResponse))
}
} else {
completion(.failure(Error.unexpectedGraphResponse))
}
}
}
}
public enum Result<T> {
case success(T)
case failure(Swift.Error)
public typealias Completion = (Result<T>) -> Void
}
有用戶的個人資料圖片,你已經知道網址,除了那個之外你還需要什麼? –