Как запросить разрешение у пользователя на предоставление доступа к его информации с помощью FB API - PullRequest
0 голосов
/ 06 февраля 2019

У меня есть код ниже, который позволяет пользователю зарегистрироваться в нашем приложении с помощью API Facebook SDK.Это работает хорошо, но я хочу попросить пользователя предоставить нам разрешение на их picture,birthday,address,email,gender,location и другую информацию.

window.fbAsyncInit = () => {
    //SDK loaded, initialize it
    FB.init({
        appId      : 'my-app-id',
        xfbml      : true,
        version    : 'v3.2'
    });

    //check user session and refresh it
    FB.getLoginStatus((response) => {
        if (response.status === 'connected') {
            //user is authorized
            document.getElementById('loginBtn').style.display = 'none';
            document.getElementById('logoutBtn').style.display = 'block';
            connectAPI(response);
        } else {

        }
    });
};

//add event listener to login button
document.getElementById('loginBtn').addEventListener('click', () => {
    //do the login
    FB.login((response) => {
        if (response.authResponse) {
            //user just authorized your app
            document.getElementById('loginBtn').style.display = 'none';

        }
    }, {
        scope: 'email', //===========change
        return_scopes: true,
        auth_type: 'rerequest'
    });
}, false);

document.getElementById('logoutBtn').addEventListener('click', () => {
    FB.logout((response) => {
        if(response.status === 'unknown'){
            document.getElementById('loginBtn').style.display = 'block';
            $('.btn-logout').hide();
        }
    });
}, false);

// Load the SDK asynchronously
(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "https://connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

//successful log in
function connectAPI(respo) {
    console.log(respo);
}

Вывод выглядит так:

enter image description here

Но я ожидаю, что вывод будет таким:

photo from google https://www.google.com/url?sa=i&source=images&cd=&cad=rja&uact=8&ved=2ahUKEwjvpcWIj6bgAhXLQN4KHUCLAN0QjRx6BAgBEAU&url=https%3A%2F%2Fwww.studytutorial.in%2Fphp-facebook-login-and-integration-in-php-website-tutorial&psig=AOvVaw1FWjb0gj6NdviN0cqfzhsk&ust=1549508480183839

Я пытался изменить эту строку:

scope: 'email'

на:

scope: 'email,name,picture,birthday,address,email,gender,location',

Но отображениевсплывающее окно выглядит следующим образом:

enter image description here

Где мне правильно вставить параметры области действия?

1 Ответ

0 голосов
/ 06 февраля 2019

Нет разрешения с именем "name" или "picture", прочитайте это: https://developers.facebook.com/docs/facebook-login/permissions

Также нет разрешения address, а разрешение location фактически называется user_location.То же самое для birthday и gender.Попробуйте с правильными и не используйте email дважды:

scope: 'email,public_profile,user_birthday,user_gender,user_location'

Не просто придумывайте разрешения, ссылка на API подскажет, какие именно существуют;)

...