Search code examples
iosobjective-cgoogle-drive-apifirebase-authenticationios11

Adding firebase to my existing iOS project which has Google Drive


I have an existing project with Google Drive API. I can use the google drive by adding the below line.

[ [ GIDSignIn sharedInstance ] setClientID:kClientID ];

GIDSignIn* signin = [ GIDSignIn sharedInstance ];    
signin.delegate = self;
signin.uiDelegate = self;
signin.scopes = [NSArray arrayWithObjects:kGTLRAuthScopeDrive, kGTLRAuthScopeDriveMetadataReadonly, nil];
[signin signIn];

And authorize the drive service with the line inside signIn:didSignInForUser:

self.driveService.authorizer = currentUser.authentication.fetcherAuthorizer;

With this, I can use all the GTLDrive API I want without a problem. Now I want to add Firebase to my project. After adding the firebase I received a new Client ID which I access as

[ GIDSignIn sharedInstance ].clientID = [ FIRApp defaultApp ].options.clientID;

Now I have to set the above clientID using FIRApp.options.cliendID else I cannot authenticate firebase.

GIDAuthentication* authentication = user.authentication;
FIRAuthCredential* credential = [ FIRGoogleAuthProvider credentialWithIDToken:authentication.idToken accessToken:authentication.accessToken ];
[ [ FIRAuth auth ] signInAndRetrieveDataWithCredential:credential completion:^(FIRAuthDataResult* authResult, NSError* error)
 {
 } ];

When I use FirAuth client ID my google drive is not working. And when I use GoogleDrive client ID firebase authentication doesn't work. I know its working as intended but, how can I have both services work for my single App.


Solution

  • Problem is solved. I didn't notice that the Firebase has created another project with the same name. Now I have same client ID. I enabled GoogleDrive API in console.developers.google.com in the new project created by Firebase and both Google Drive and Firebase API authorized without an issue.