gpt4 book ai didi

ios - Flutter 使用 Facebook 登录

转载 作者:行者123 更新时间:2023-11-29 05:14:01 24 4
gpt4 key购买 nike

我正在尝试使用 Facebook 登录我的用户。因此,我使用这段代码:

 FacebookLoginResult facebookLoginResult = await _handleFBSignIn();
final accessToken = facebookLoginResult.accessToken.token;
if (facebookLoginResult.status == FacebookLoginStatus.loggedIn) {
setState(() {
isSaving = true;
});

final facebookAuthCred =
FacebookAuthProvider.getCredential(accessToken: accessToken);
final user =
await firebaseAuth.signInWithCredential(facebookAuthCred);

final graphResponse = await http.get(
'https://graph.facebook.com/v4.0/me?fields=name,first_name,last_name,friends,email&access_token=$accessToken');
final profile = jsonDecode(graphResponse.body);

if (profile['id'] != null) {
setState(() {
facebookID = profile['id'];
});
}

Future<FacebookLoginResult> _handleFBSignIn() async {
FacebookLogin facebookLogin = FacebookLogin();
FacebookLoginResult facebookLoginResult =
await facebookLogin.logInWithReadPermissions(['email', 'user_friends']);
switch (facebookLoginResult.status) {
case FacebookLoginStatus.cancelledByUser:
print("Cancelled");
break;
case FacebookLoginStatus.error:
print("error");
break;
case FacebookLoginStatus.loggedIn:
print("Logged In");
break;
}
return facebookLoginResult;
}

这在 Android 上完美运行,但在 ios 上我收到错误。

flutter: Cancelled
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The getter 'token' was called on null.
Receiver: null

所以我假设它与我的 info.plist 有关,因为 android 没有这个问题。我查看了 info.plist 但找不到任何内容...

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>drinkm8</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSCameraUsageDescription</key>
<string>Hiermee kunt u een verhaal maken</string>
<key>NSContactsUsageDescription</key>
<string>Your prompt</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Always/When in use description</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Can I haz location always?</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app needs access to location when open.</string>
<key>NSMicrophoneUsageDescription</key>
<string>Hiermee kunt u een verhaal maken</string>
<key>NSMotionUsageDescription</key>
<string>Motion Usage Description</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Hiermee kunt u een foto selecteren</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Hiermee kunt u een foto opslaan</string>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
<string>remote-notification</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>FirebaseAppDelegateProxyEnabled</key>
<string>NO</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<!-- TODO Replace this value: -->
<!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID -->
<string>com.googleusercontent.apps.myappid</string>
<string>fb4856myappid</string>
</array>
</dict>
</array>
<key>FacebookAppID</key>
<string>4856myappid</string>
<key>FacebookDisplayName</key>
<string>DRINKM8</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
</array>
<key>io.flutter.embedded_views_preview</key>
<string>YES</string>
</dict>
</plist>

我是否错过了为 ios 安装 FB 的步骤(我只编辑了 info.plist 并将 fb 登录添加到 pubspec yaml)?

提前致谢!

最佳答案

我从 github 了解到这是包或 sdk 中的错误或......

但是对于 IOS,如果你使用这个就可以了:

final fbLogin =FacebookLogin();
fbLogin.loginBehavior = FacebookLoginBehavior.webViewOnly;

关于ios - Flutter 使用 Facebook 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59377718/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com