Angular 4应用ngx-facebook插件触发Facebook登录权限页问题求助
解决Angular 4中ngx-facebook登录再次触发权限页面的问题
嘿,这个问题其实是Facebook登录机制的默认行为导致的——当用户已经拒绝过某些权限后,再次调用常规的login()方法时,Facebook会默认跳过权限请求步骤,直接返回当前已授权的权限。要重新触发权限请求页面,你需要在登录选项里添加auth_type参数。
具体修改方案
你只需要在LoginOptions中添加auth_type: 'rerequest'(或者'reauthenticate',根据需求选择),这样就能强制Facebook再次弹出权限请求页面,让用户重新选择权限:
import { FacebookService, InitParams, LoginResponse, LoginOptions } from 'ngx-facebook'; export class LoginComponent implements OnInit { constructor(private fb: FacebookService){} fbLogin() { const loginOptions: LoginOptions = { enable_profile_selector: true, return_scopes: true, scope: 'user_birthday,user_photos,email,public_profile', // 添加这行代码,强制重新请求权限 auth_type: 'rerequest' } this.fb.login(loginOptions).then((response) => { let array = response.authResponse.grantedScopes.split(','); if(array.length == 4){ // 权限全部获取完成的逻辑 }else{ this.ajaxService.alertError('You need to provide all the facebook permissions to use the app.'); } }); } }
参数说明
auth_type: 'rerequest':专门用于重新请求用户之前拒绝过的权限,只会弹出用户未授权的那些权限的请求页,用户体验更友好。- 如果用
auth_type: 'reauthenticate':会让用户重新输入Facebook密码,同时重新请求所有指定的权限,适合需要强验证的场景。
额外注意事项
如果用户完全拒绝了所有权限或者在Facebook设置里撤销了你的应用权限,那么即使不加auth_type,再次登录也会重新弹出权限页。但针对用户拒绝部分权限的场景,rerequest是最适合的方案。
内容的提问来源于stack exchange,提问作者Anil Shrestha
相关产品推荐
相关产品推荐

