dart Flutter Firebase Twitter Auth抛出错误

l7mqbcuq  于 2023-04-27  发布在  Flutter
关注(0)|答案(2)|浏览(144)

我正在尝试将Twitter auth整合到我的Flutter应用程序中。我正在遵循FlutterFire文档,但我抛出了一个错误。我想知道是否在我的终端或Twitter登录插件上存在问题。下面是我的代码:

Future<UserCredential> signInWithTwitter() async {
    // Create a TwitterLogin instance
    final twitterLogin = new TwitterLogin(
        apiKey: '<1qOvE68aiVbk4URSARlfm0758>',
        apiSecretKey: ' <wQHWRYBweiV5DvEecSUTeSbnT6uwB6080D4vz6WDyY1geT8Paz>',
        redirectURI: '<twitter-firebase-auth>://');

    // Trigger the sign-in flow
    final authResult = twitterLogin.login();

    // Create a credential from the access token
    final twitterAuthCredential = TwitterAuthProvider.credential(
      accessToken: authResult.authToken!,
      secret: authResult.authTokenSecret!,
    );

    // Once signed in, return the UserCredential
    return await FirebaseAuth.instance
        .signInWithCredential(twitterAuthCredential);
  }

我得到以下错误:

The getter 'authToken' isn't defined for the type 'Future<AuthResult>'.
Try importing the library that defines 'authToken', correcting the name to the name of an existing getter, or defining a getter or field named 'authToken'.
lbsnaicq

lbsnaicq1#

你应该去

final authResult = await twitterLogin.login();
xuo3flqw

xuo3flqw2#

@克塔内穆尔说得对
你只需要在twitterLogin.login()之前添加await;
所以最终的代码应该是这样的。

Future<UserCredential> signInWithTwitter() async {
// Create a TwitterLogin instance
final twitterLogin = new TwitterLogin(
    apiKey: '<1qOvE68aiVbk4URSARlfm0758>',
    apiSecretKey: ' <wQHWRYBweiV5DvEecSUTeSbnT6uwB6080D4vz6WDyY1geT8Paz>',
    redirectURI: '<twitter-firebase-auth>://');

// Trigger the sign-in flow
final authResult = await twitterLogin.login();

// Create a credential from the access token
final twitterAuthCredential = TwitterAuthProvider.credential(
  accessToken: authResult.authToken!,
  secret: authResult.authTokenSecret!,
);

// Once signed in, return the UserCredential
return await FirebaseAuth.instance
    .signInWithCredential(twitterAuthCredential);

}
然后我认为'authToken'没有为类型'Future'定义错误应该得到解决。

相关问题