如何在Facebook和Twitter上快速验证到Firebase的身份?

时间:2019-11-26 07:29:36

标签: facebook authentication flutter twitter dart

我正在尝试通过faceboook和twitter进行身份验证,并完成了facebook Developr console的setUp部分,并实现了Facebook登录方法以执行Dart代码,但为什么在发生错误? Hello **(C)**world, nice to **(D)**meet you, You are **(G)** my sunshine, my **(Em)** only sunshine. 。 但是我正在关注dart软件包网站facebook_sign_in插件

代码:

function onOpen() {
  DocumentApp.getUi()
      .createMenu('Utilities')
      .addItem('Bold Parentheses', 'replaceParentheses')
      .addToUi();
};

function replaceParentheses() {
  var body = DocumentApp.getActiveDocument().getBody();      

  var found = body.findText("\\(.+?\\)");
  while (found) {
    var elem = found.getElement();
    if (found.isPartial()) {
      var start = found.getStartOffset();
      var end = found.getEndOffsetInclusive();
      elem.setBold(start, end, true);
    }
    else {
      elem.setBold(true);
    }
    found = body.findText("\\(.+?\\)", found);
  }
};

enter image description here

Twitter身份验证方法

facebookLogin.logInWithReadPermission

Twitter登录按钮:


 Future<FirebaseUser> signInWithFacebook()async{
   FacebookLogin facebookLogin = new FacebookLogin();
   final FacebookLoginResult result = await facebookLogin.logInWithReadPermissions(['email']);
 }

例外,当单击Twitter登录按钮时:

Future<bool> signInWithTwitterAccount()async{
  setState(() {
     isLoading=true;
   });
    try{
    TwitterLogin twitterLogin = new TwitterLogin(
      consumerKey: consumerApiKey,
      consumerSecret: consumerSecretApiKey
    );
    TwitterLoginResult  _twitterLoginResult = await twitterLogin.authorize();
     TwitterSession _currentUserTwitterSession = _twitterLoginResult.session;
     AuthCredential authCredential = TwitterAuthProvider.getCredential(
        authToken: _currentUserTwitterSession.token,
        authTokenSecret: _currentUserTwitterSession.secret
     );
     AuthResult result = await auth.signInWithCredential(authCredential);
      if(result.user== null)
        return false;
      return true;
    }catch(error){
      Fluttertoast.showToast(msg: "Log in Error at :$error");
      return false;
    }
 }

1 个答案:

答案 0 :(得分:1)

似乎最新版本中没有logInWithReadPermission方法。从他们的存储库中可以看到: https://github.com/roughike/flutter_facebook_login/blob/master/lib/flutter_facebook_login.dart

您可以尝试如示例代码中所示登录,该示例代码使用“ logIn”功能代替logInWithPermission,请查看存储库示例here

import 'dart:async';

import 'package:flutter_facebook_login/flutter_facebook_login.dart';
import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State<MyApp> {
  static final FacebookLogin facebookSignIn = new FacebookLogin();

  String _message = 'Log in/out by pressing the buttons below.';

  Future<Null> _login() async {
    final FacebookLoginResult result =
        await facebookSignIn.logIn(['email']);

    switch (result.status) {
      case FacebookLoginStatus.loggedIn:
        final FacebookAccessToken accessToken = result.accessToken;
        _showMessage('''
         Logged in!

         Token: ${accessToken.token}
         User id: ${accessToken.userId}
         Expires: ${accessToken.expires}
         Permissions: ${accessToken.permissions}
         Declined permissions: ${accessToken.declinedPermissions}
         ''');
        break;
      case FacebookLoginStatus.cancelledByUser:
        _showMessage('Login cancelled by the user.');
        break;
      case FacebookLoginStatus.error:
        _showMessage('Something went wrong with the login process.\n'
            'Here\'s the error Facebook gave us: ${result.errorMessage}');
        break;
    }
  }

  Future<Null> _logOut() async {
    await facebookSignIn.logOut();
    _showMessage('Logged out.');
  }

  void _showMessage(String message) {
    setState(() {
      _message = message;
    });
  }

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('Plugin example app'),
        ),
        body: new Center(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new Text(_message),
              new RaisedButton(
                onPressed: _login,
                child: new Text('Log in'),
              ),
              new RaisedButton(
                onPressed: _logOut,
                child: new Text('Logout'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}