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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -