How to determine the default avatar on facebook?

How to determine the default avatar from the link https://graph.facebook.com/'.$id.'/picture?type=large:? Is this the only way to get avatars (men / women) from specially prepared profiles, and then compare, for example, md5 ()?

It is hard to believe that this is the only way.

+3
source share
4 answers

You can use the parameter redirect=false:

https://graph.facebook.com/naitik/picture?redirect=false

Then facebook responds jsonand contains the following data:

{
   "data": {
      "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/157337_5526183_369516251_q.jpg",
      "is_silhouette": false
   }
}

You can use the parameter is_silhouetteto determine if the photo is the default.

: https://developers.facebook.com/docs/reference/api/using-pictures/

+20

If you are already accessing the Graph API to get user data, such as an avatar, just include picturein the fields param when you make your first call to the Graph API, then the response will include an offset is_silhouette, if set to true, the user has an avatar default.

Inquiry:

https://graph.facebook.com/v2.7/me?access_token=[token]&fields=name,picture

Answer:

{
    "id": "100103095474350",
    "name": "John Smith",
    "picture": {
        "data": {
            "is_silhouette": true,
            "url": "https://scontent.xx.fbcdn.net/v/...jpg"
        }
    }
}
0
source

Using the Facebook SDK for 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
}
0
source

All Articles