ios - Fetch Google profile image url by UID -
i want fetch google profile image when uid given me . have this reference m getting how hit url . please provide me example.
edit: here code
var googleimageurl: url?{ let urlstring = "https://www.googleapis.com/plus/v1/people/\(uid)?fields=image&key=aizasybfjhpl8dju0igw9mxbvk6honpy" return url(string: urlstring) } alamofire.request(url) .validate() .responsejson(completionhandler: { (response) in if response.result.issuccess { let json = response.result.value as? [string: any] } else { let apierror = apierror(response: response) } })
when hitting api, getting error. why not getting response ?
you have 2 options:
using googles api, requires api key:
https://www.googleapis.com/plus/v1/people/{uid}?fields=image&key={your_api_key}
using googles picasaweb not require api key:
http://picasaweb.google.com/data/entry/api/user/{uid}?alt=json
code image:
// check want return in oncompletion , use func getimage(uid: string, oncompletion: @escaping (string) -> void, onerror: @escaping (nserror) -> void) { let url = "https://www.googleapis.com/plus/v1/people/\(uid)?fields=image&key=aizasybfjhpl8dju0igw9mxbvk6honpy" let headers = [ "content-type": "application/json" ] alamofire.request(url, method: .get, parameters: nil, encoding: jsonencoding.default, headers: headers) .responsejson { response in if let object = response.result.value as? [string:any] { print(object) // use oncompletion in here } } }
Comments
Post a Comment