Skip to content

Commit

Permalink
added key api from google service
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardik Garg committed Feb 2, 2024
1 parent 58d12c2 commit 894ee3f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions ios/OpenBot/OpenBot/Authentication/Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ class Authentication {
// Show the sign-out button and hide the GIDSignInButton
}
}

/**
static method to get api key from google-service
*/
static func getGoogleAPIKey() -> String {
if let path = Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist"),
let dict = NSDictionary(contentsOfFile: path),
let apiKey = dict["API_KEY"] as? String {
return apiKey
}
return ""
}

/**
static method to download a file
Expand All @@ -138,8 +150,9 @@ class Authentication {
- completion:
*/
static func download(file: String, completion: @escaping (_ data: Data?, _ error: Error?) -> Void) {
let APIkey = getGoogleAPIKey();
let fileId = returnFileId(fileLink: file);
let url = "https://www.googleapis.com/drive/v3/files/\(fileId)?alt=media&key=AIzaSyCITlkh63TnSnJQBlzqbJwwtBDr_w3e1Pg" //key extracted from google console
let url = "https://www.googleapis.com/drive/v3/files/\(fileId)?alt=media&key=\(APIkey)";
let service: GTLRDriveService = GTLRDriveService();
let fetcher = service.fetcherService.fetcher(withURLString: url)
fetcher.beginFetch(completionHandler: { data, error in
Expand All @@ -162,7 +175,8 @@ class Authentication {
*/

static func download(fileId: String, completion: @escaping (_ data: Data?, _ error: Error?) -> Void) {
let url = "https://www.googleapis.com/drive/v3/files/\(fileId)?alt=media&key=AIzaSyCITlkh63TnSnJQBlzqbJwwtBDr_w3e1Pg" //key extracted from google console
let APIkey = getGoogleAPIKey();
let url = "https://www.googleapis.com/drive/v3/files/\(fileId)?alt=media&key=\(APIkey)";
let service: GTLRDriveService = GTLRDriveService()
let fetcher = service.fetcherService.fetcher(withURLString: url)
fetcher.beginFetch(completionHandler: { data, error in
Expand Down

0 comments on commit 894ee3f

Please sign in to comment.