Twitterログインを使用してFirebaseにユーザー(FIRUser)を作成しようとした場合に、Twitterのログインは成功しているものの FIRAuth.auth()?.signIn(with: credential
時に以下のようなメッセージのエラーが発生してしまう問題にぶつかりました。
Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={NSUnderlyingError=0x608000253d40 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={ code = 400; errors = ( { domain = global; message = "Network error while to fetch VERIFY_CREDENTIAL from TWITTER."; reason = invalid; } ); message = "Network error while to fetch VERIFY_CREDENTIAL from TWITTER."; }}}, error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information.}
これはこのメッセージだけではわかりません。原因はFabricのようです。以下のサイトにズバリ回答が書かれていました。
AppDelegateでAPIキーとAPIシークレットを改めて設定してあげる必要がありそうです。これにならって修正しようと思いますが、ついでにinfo.plistに以下のようにキーとシークレットの文字列を書き込む形(「TwitterKey」というDictionaryを作り、「TwitterConsumerKey」「TwitterConsumerSecret」という文字列を内包する感じにしました。)にしてそれをコードで拾うような形にして設定してみようと思います。
AppDelegateの FIRApp.configure()
まではこんな感じです。
let twKey = Bundle.main.infoDictionary!["TwitterKey"] as! Dictionary<String,AnyObject> let TwitterConsumerKey = twKey["TwitterConsumerKey"]! as! String let TwitterConsumerSecret = twKey["TwitterConsumerSecret"]! as! String Twitter.sharedInstance().start(withConsumerKey: TwitterConsumerKey, consumerSecret: TwitterConsumerSecret) Fabric.with([Twitter.self]) FIRApp.configure()
以上の修正を加えて実行するとうまくいくようになると思います。
東京造形大学卒業後、マクロメディア(現アドビ)に入社。QAやテクニカルサポートマネージャーとしてFlash、DreamweaverなどのWeb製品を担当。独立後、2007年に虫カゴデザインスタジオ株式会社を設立。2021年東京三鷹を拠点に。最近は、Unity, Unity Netcode for GameObjects, CakePHP, Laravel, ZBrush, Modo, Adobe Substance 3D, Adobe Firefly, Xcode, Apple Vision Pro, Firebaseにフォーカスしています。モバイルアプリ開発情報を主としたブログ「MUSHIKAGO APPS MEMO」の中の人。