我正在使用 Cordova 开发一个旧的 Ionic 应用程序,并尝试使用 Facebook 登录,具体来说是使用 cordova-plugin-facebook-connect 插件。登录过程似乎有效,但是
我正在使用 Cordova 开发一个旧的 Ionic 应用程序,并尝试使用 Facebook 登录,特别是使用 cordova-plugin-facebook-connect 插件。登录过程似乎有效,但成功登录后,应用程序会重定向回登录屏幕,并且应用程序内的点击无响应。
环境:Ionic 框架:7.2.0,Cordova:12.0.0( [email protected] ),cordova-plugin-facebook-connect\':\'^3.2.0,
Package.json:\'cordova-plugin-facebook-connect\':{\'APP_ID\':\'.....\',\'APP_NAME\':\'...\',\'FACEBOOK_URL_SCHEME_SUFFIX\':\' \',\'OTHER_APP_SCHEMES\':\' \',\'FACEBOOK_AUTO_LOG_APP_EVENTS\':\'true\',\'FACEBOOK_HYBRID_APP_EVENTS\':\'false\',\'FACEBOOK_ADVERTISER_ID_COLLECTION\':\'true\',\'FACEBOOK_ANDROID_SDK_VERSION\':\'14.1.0\',\'FACEBOOK_IOS_SDK_VERSION\': \'11.1.0\',\'FACEBOOK_BROWSER_SDK_VERSION\':\'v11.0\'}
代码 :
async fbLogin() {
try {
if (this.platform.is("cordova")) {
const response = await this.fb.login(["public_profile", "email"]);
if (response.status === "connected") {
console.error("Facebook login Succeed");
this.isLoggedIn = true;
this.getFBUserDetail(res.authResponse.userID);
} else {
console.error("Facebook login failed:", response);
this.isLoggedIn = false;
}
} else {
console.error("Facebook login is only available on device");
}
} catch (error) {
console.error("Error during Facebook login:", error);
}
}
a
nd
getFBUserDetail(userid: any) {
this.fb
.api(
"/" + userid + "/?fields=id,email,name,first_name,last_name,picture",
["public_profile"]
)
.then((res) => {
this.users = res;
let formData = {
customer_name: this.users.first_name,
customer_lastname: this.users.last_name,
customer_email: this.users.email,
fb_id: this.users.id,
image: this.users.picture.data.url,
};
this.loaderService.show("PLEASE_WAIT");
this.api.post("fb_login", formData).subscribe(
(res: any) => {
this.loaderService.hideAll();
this.storage.set("USER_ID", res.response.customer_id);
this.storage.set("USER_NAME", this.users.first_name + " " + this.users.last_name);
this.storage.set("USER_IMAGE", this.users.picture.data.url);
this.storage.set("USER_EMAIL", this.users.email);
this.storage.set("USER_REFERRAL_CODE", res.response.refer_code);
this.storage.set("USER_DETAILS", res.response);
this.GlobalobservablesService.publishData({ APP_NAME: "order_status" });
this.loaderService.showToast(this.translate.instant("LOGIN_SUCCESS"));
setTimeout(() => {
this.route.navigate(["./home"]);
});
},
(err) => {
this.loaderService.hideAll();
}
);
})
.catch((e) => {
console.error("Error during getting Facebook details:", e);
});
}
问题摘要:Facebook 登录成功后,应用程序将重定向回登录屏幕。点击和交互变得无响应。在 Chrome DevTools 中登录尝试后没有出现任何日志或错误。
其他详细信息:我在 ConnectPlugin.java 中注释掉了 AppEventsLogger.deactivateApp(cordova.getActivity().getApplication()); 因为它导致构建失败。