防火墙身份验证(分别使用twitter_login: ^4.0.1
和flutter_facebook_auth: ^4.0.1
)。我在两个身份验证过程中都会出现错误。我还在开发人员帐户中设置了Facebook Login
和Twitter Login
。也在网上浏览了很多文章,但似乎都没有用。在最近的更新之后。
收到的错误消息:
E/com.facebook.GraphResponse(13052): {HttpStatus: 400, errorCode: 100, subErrorCode: 33, errorType: GraphMethodException, errorMessage: Unsupported get request. Object with ID 'XXXXXXXXXXXX' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api}
以上信息来自Facebook,下面来自Twitter
E/flutter (13052): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(400, Failed to generate request token., Please check your APIKey or APISecret., null)
AndroidManifest.xml
文件
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<data android:scheme="twitter-firebase-auth"/>
</intent-filter>
</activity>
pubspec.yaml
包,
flutter_facebook_auth: 4.0.0
twitter_login: 4.0.1
firebase_auth: 3.3.5
firebase_core: 1.11.0
Facebook登录:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';
var title = "";
var displayName = "";
FirebaseAuth auth = FirebaseAuth.instance;
signInWithFacebook() async {
try {
final LoginResult result = await FacebookAuth.instance.login();
switch (result.status) {
case LoginStatus.success:
final AuthCredential credential =
FacebookAuthProvider.credential(result.accessToken!.token);
if (kDebugMode) {
print(result.accessToken!.token);
}
final userCredential = await auth.signInWithCredential(credential);
if (kDebugMode) {
print(credential.signInMethod);
}
// TODO: Store user.credential!.signInMethod in SharedPref.
if (kDebugMode) {
print(userCredential.user!.displayName);
}
// boolean isLoggedIn = accessToken != null && !accessToken.isExpired();
if (kDebugMode) {
print("status: Status.Success");
}
break;
case LoginStatus.cancelled:
if (kDebugMode) {
print("status: Status.Cancelled");
}
break;
case LoginStatus.failed:
if (kDebugMode) {
print("status: Status.Failed");
}
break;
default:
if (kDebugMode) {
print("null");
}
break;
}
} catch (e) {
if (kDebugMode) {
print('Error occurred!' + e.toString());
}
}
}
Twitter登录
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/foundation.dart';
import 'package:twitter_login/twitter_login.dart';
FirebaseAuth _auth = FirebaseAuth.instance;
signInWithTwitter() async {
final twitterLogin = TwitterLogin(
apiKey: "XXXXXXXXXXXXXX",
apiSecretKey: "XXXXXXXXXXXXXXXXXXXX",
redirectURI: "twitter-firebase-auth://",
);
final authResult = await twitterLogin.login();
switch (authResult.status) {
case TwitterLoginStatus.loggedIn:
if (kDebugMode) {
print("status: LogIn Success");
}
final AuthCredential twitterAuthCredential =
TwitterAuthProvider.credential(
accessToken: authResult.authToken!,
secret: authResult.authTokenSecret!);
final userCredential =
await _auth.signInWithCredential(twitterAuthCredential);
if (kDebugMode) {
print("status: SignIn With Credential Success");
}
break;
case TwitterLoginStatus.cancelledByUser:
if (kDebugMode) {
print("status: Cancelled By User");
}
break;
case TwitterLoginStatus.error:
if (kDebugMode) {
print("status: Error");
}
break;
default:
if (kDebugMode) {
print("status: null");
}
}
}
发布于 2022-02-01 09:08:02
问题解决了,
Twitter解决方案:
(查看了twitter_login:^4.0.1文档)。
<data android:scheme="flutter-twitter-auth"/>
将上面的内容改为,
<data android:scheme="your_app_name"/>
也可以替换下面的片段
final twitterLogin = TwitterLogin(
apiKey: "xxxxxxxxxx",
apiSecretKey: "xxxxxxxxx",
redirectURI: 'flutter-twitter-auth://',
);
使用
final twitterLogin = TwitterLogin(
apiKey: "xxxxxxxxxx",
apiSecretKey: "xxxxxxxxx",
redirectURI: 'your_app_name://',
);
最后,twitter开发人员帐户中的回调URL应该是,
your_app_name://
更改的XML文件:
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<data android:scheme="twitter-firebase-auth"/>
</intent-filter>
</activity>
如下所示:
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="buildyourenglish"/>
</intent-filter>
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
Facebook解决方案:
获取客户端令牌,如下所示:
应用程序仪表板->设置->高级->安全-> Client_Token (您的facebook客户端令牌)
转到Project_Folder -> android ->应用程序-> src -> main -> res -> values -> value.xml (如果没有创建)并粘贴以下代码。
同样,转到Project_Folder -> android ->应用程序-> src -> main -> res -> values -> value.xml (如果没有创建)并粘贴以下代码。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">your_app_name</string>
<string name="facebook_app_id">your_facebook_app_id</string>
<string name="fb_login_protocol_scheme">your_fb_login_protocol_scheme (fb+your_facebook_app_id)</string>
<string name="facebook_client_token">your_facebook_client_token</string>
</resources>
并从以下链接生成哈希键:
http://tomeko.net/online_tools/hex_to_base64.php
必须将SHA1:
作为输入。( tomeko.net和stackoverflow.com提供)
https://stackoverflow.com/questions/70937933
复制相似问题