我试图在我的项目中添加Twitter登录方法。当我在项目中尝试它时,网上几乎没有几行代码,这会抛出错误。有人可以帮我吗

这是我的代码:

 Future<FirebaseUser> loginWithTwitter() async {
  var twitterLogin = new TwitterLogin(
    consumerKey: 'Y2MyConsumerKeyYKX',
    consumerSecret: 'xYXUMyConsumerSecretKeyjFAJZMyConsumerSecretKeyS3i',
  );

  final TwitterLoginResult result = await twitterLogin.authorize();

  switch (result.status) {
    case TwitterLoginStatus.loggedIn:
      var session=result.session;
      final AuthCredential credential= TwitterAuthProvider.getCredential(
          authToken: session.token,
          authTokenSecret: session.secret
      );
      FirebaseUser firebaseUser=(await _auth.signInWithCredential(credential)).user;
      print("twitter sign in"+firebaseUser.toString());
      break;
    case TwitterLoginStatus.cancelledByUser:
      break;
    case TwitterLoginStatus.error:
      break;
  }
  return null;
}

错误与SignInWithTwitter和Debug print命令有关。有人可以帮助我吗?
enter image description here

firebase - 在flutter类中定义的 &#39;SignInWithTwitter isn&#39;方法-LMLPHP

最佳答案

FirebaseAuth不包含名为signInWithTwitter的方法,如果您想使用Twitter登录,则需要使用 TwitterAuthProvider

例如:

switch (result.status) {
  case TwitterLoginStatus.loggedIn:
    var session=result.session;
    final AuthCredential credential= TwitterAuthProvider.getCredential(
      authToken: session.token,
      authTokenSecret: session.secret
    );
    FirebaseUser firebaseUser=(await firebaseAuth.signInWithCredential(credential)).user;
    print("twitter sign in"+firebaseUser.toString());
    break;
  case TwitterLoginStatus.cancelledByUser:
    break;
  case TwitterLoginStatus.error:
    break;
}

getCredential内部,您可以添加authTokenauthTokenSecret,然后将变量作为参数传递给signInWithCredentials

07-24 13:19