0

In firebase console I can get this source code for java and some adminsdk json file to download. However I'm working in c# xamarin and it doesn't have the setCredential() function. This is java code that I can download in firebase console

FileInputStream serviceAccount = new FileInputStream("path/to/serviceAccountKey.json");

FirebaseOptions options = new FirebaseOptions.Builder()
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
.setDatabaseUrl("https://abc-def.firebaseio.com")
.build();

FirebaseApp.initializeApp(options);

But in xamarin, there is no SetCredential function. I can do only things like:

 FirebaseOptions options = new FirebaseOptions.Builder()
     .SetApplicationId("1:3465124113567:android:81db52b2352255cd")
     .SetDatabaseUrl("https://abc-def.firebaseio.com/")
     .SetStorageBucket("gs://abc-def.appspot.com")
     .SetApiKey("???")
     .SetGcmSenderId("???")
     .Build();
 var firebaseApp = FirebaseApp.InitializeApp(context, options);

How can I use that file? I made couple of tries in SetApiKey, setting some lines from that file, but somehow the application is just crashing on InitializeApp line, without meaningfull explanation in output window. How is it done that my application gets admin privileges in c# - xamarin?

In this question I found that SetCredentials wasn't there always, but all my xamarin.firebase.xxx components are on version 10.2.1 so this shouldn't be problem.

hoacin
  • 340
  • 1
  • 2
  • 19

1 Answers1

1

Refer to @Doug Stevenson 's answer, you are using the Firebase Android client library, not the Firebase Admin SDK. You could read the javadoc for FirebaseOptions.Builder in the Android client library :

Android : FirebaseOptions.Builder

Then look at the same class from the java Admin SDK (note the URL is different) :

Admin SDK : FirebaseOptions.Builder

They are different things, in your project you are using the Android SDK definition and not the admin SDK definition.

York Shen
  • 9,014
  • 1
  • 16
  • 40
  • I will look at that after weekend. Thank you. – hoacin Dec 08 '17 at 11:14
  • I tried to put admin SDK to the same code with normal sdk, just under some #if conditions, but it looks that it would be too messy. I think I must find another way. Or you think I should give it a try? – hoacin Dec 13 '17 at 07:01
  • 1
    @hoacin, as Doug Stevenson said, "The SDKs both provide classes with the exact same package and class name, so it wouldn't possibly be able to use them both at the same time". – York Shen Dec 13 '17 at 07:33