fb.login応答は常にtrueを返します
-
12-12-2019 - |
質問
SEERが必要な許可をすべて与えたかどうかを確認するために、それを実行します。
FB.login(function(response){
console.log(response.status);
if (response.status == 'connected') {
/* user gave permssions */
}else{
/* user didnt, unmark the checkbox */
$('input:checkbox').removeAttr('checked');
}
}, { scope: 'publish_stream' });
.
問題は、これがAllways Trueであることです。ユーザー:ログイン、ommit、またはpopupを閉じるか閉じた場合は問題がありません。
なぜですか?
も試してみました:if(response.authResponse){成功のない
解決
publish_stream
は拡張権限ユーザーはその許可からオプトアウトできます。一般的に言って、ユーザーがコールバックのコードブロックにヒットしたとき、それらはアプリを認証しましたが、それらの一部が拡張権限。 response.status
は、要求したダイアログプロンプト/権限のすべてを受け入れたかどうかではなく、ユーザーがアプリケーションを認証したかどうかのステータスを通信するためにのみ使用されます。あなたの場合、publish_stream
は拡張権限ですので、コールバックでユーザーのその許可を持つことが保証されていません。ユーザーがすでに認証されていると、publish_stream
を増分許可として求める場合、response.status
の条件付きチェックは常にtrueを返します(定義によってはすでにアプリケーションを認証しているため)。
コールバックにpublish_stream
権限を持っていることを確認したい場合は、Graph APIの/me/permissions
エンドポイントを使用して権限を確認してください。
あなたが欲しいものはこのようなものです:
FB.login(function(response){
if (response.status == 'connected') {
FB.api('/me/permissions', function(response) {
var permsArray = response.data[0];
// Permissions that are needed for the app
var permsNeeded = ['publish_stream'];
var permsToPrompt = [];
for (var i in permsNeeded) {
if (permsArray[permsNeeded[i]] == null) {
permsToPrompt.push(permsNeeded[i]);
}
}
if (permsToPrompt.length > 0) {
$('input:checkbox').removeAttr('checked');
}
}
} else {
/* user didnt, unmark the checkbox */
$('input:checkbox').removeAttr('checked');
}
}, { scope: 'publish_stream' });
. 他のヒント
私は理由がわからないが、以下のコードは少なくとも〜
に問題ない。window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo FACEBOOK_APP_ID ?>',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
FB.getLoginStatus(function(response){
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
var signed_request = response.authResponse.signedRequest;
// avoid using cookie
self.location= "<?php echo site_url()?>/signup/fb_login/"+uid;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
FB.login(function(response) {
if (response.authResponse) {
self.location="<?php echo site_url()?>/signup/fb_register";
/* FB.api('/me', function(response) { */
/* }); */
} }, {scope: 'email,user_hometown'});
} else { // unknown
// the user isn't logged in to Facebook.
}
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
.
所属していません StackOverflow