2017-12-26 22 views
0

私はラズベリーPIから実行され、firebaseデータベースに接続するアプリケーションを作成しようとしています。私はこのアプリをC++で書いており、簡単な方法があるのだろうかと思っていました。C++ Firebaseラッパー?

私はモジュールPyrebaseとPythonでそれをやった:

import pyrebase 

def firbaseLogIn(): 
    directory = os.getcwd() 
    serviceAccount = directory + "xxx.json" 

    config = { 
     "apiKey": "xxx", 
     "authDomain": "xxxx", 
     "databaseURL": "https://example.com", 
     "projectId": "xxxx", 
     "storageBucket": "xx.example.com", 
     "serviceAccount": serviceAccount 
    } 

    firebase = pyrebase.initialize_app(config) 

    # Log the user in 
    email = "[email protected]" 
    password = "xxx" 

    auth = firebase.auth() 
    user = auth.sign_in_with_email_and_password(email, password) 


    # Get a reference to the database service 
    db = firebase.database() 

    # Pass the user's idToken to the push method 
    userInfo = db.child("users").child(user['localId']).get() 
    print(userInfo.val()) 

    return; 

、それが正常に動作します。しかし、私がC++ SDKと似たようなことをやろうとしたときに、そのアプリケーションのドキュメントに従うだけでは機能しません。私はそれがIOSゲーム(実際にはXcodeが必要だと言われています)としか動作しないためか、ドキュメントを正しく読むことができないためです。 コードはエラーをスローしません。私が正しくサインインしたが、ユーザ情報が正しくないと表示されます。例えば、UIDは電子メールであり、電話番号は1-888-897-5309であり、これは明らかに正しくありません。

これは、私はC++で試してみたものです:

#include "firebase/app.h" 

firebase::App* configureFirebaseApp(std::string appcwd){ 

    std::string stringAppID = appcwd + "xxx.json"; 
    const char* appID = &stringAppID[0]; 

    firebase::AppOptions appOptions = firebase::AppOptions(); 
    appOptions.set_api_key("xxx"); 
    appOptions.set_database_url("https://xxx.xxx.com"); 
    appOptions.set_project_id("xxx"); 
    appOptions.set_storage_bucket("xxxxx.xxxx.com"); 
    appOptions.set_app_id(appID); 

    return firebase::App::Create(appOptions); 
} 

#include "firebase/auth.h" 

void FirebaseLogIn(std::string appcwd){ 

    const char email[] = "[email protected]"; 
    const char password[] = "xxxxx"; 

    std::cout<<"Configuring app...\n"; 
    firebase::App* app = configureFirebaseApp(appcwd); 

    // Get the Auth class for your App. 
    firebase::auth::Auth* auth = firebase::auth::Auth::GetAuth(app); 

    std::cout<<"Signing in...\n"; 
    // Request anonymous sign-in and wait until asynchronous call completes. 
    firebase::Future<firebase::auth::User*> result = 
     auth->SignInWithEmailAndPassword(email, password); 

    if (result.status() == firebase::kFutureStatusComplete) { 
     if (result.error() == firebase::auth::kAuthErrorNone) { 
     firebase::auth::User* user = *result.result(); 
     printf("Log in user succeeded for email %s\n", user->email().c_str()); 
     std::cout << "Name: " << user->display_name() << std::endl; 
     std::cout << "uid: " << user->uid() << std::endl; 
     std::cout << "email: " << user->email() << std::endl; 
     std::cout << "phone number: " << user->phone_number() << std::endl; 
     } else { 
     printf("Log in user failed with error '%s'\n", result.error_message()); 
     } 
    } 

はあなたが与えることができるかもしれ任意の助けてくれてありがとう。

答えて

0

公式Firebase SDK for C++は、ネイティブのAndroid SDKとiOS SDKのラッパーです。したがって、これらのプラットフォームでのみ実行されます。

異なるプラットフォームをターゲットにする場合は、別のライブラリが必要です。通常、このようなライブラリは特定の製品のFirebase REST API(Pyrebaseがデータベースの場合など)をラップするため、プラットフォーム間で動作する可能性が高くなります。