如何检测链接上的默认头像是这样的: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
}
有用户的个人资料图片,你已经知道网址,除了那个之外你还需要什么? –