0

私の Facebook キャンバス アプリでは、ユーザーのメールにアクセスしようとしています。お願いしても出てこない(追加の許可でもある誕生日は出てくる)。(addscope 関数内)

<html>
<head></head>
<body>
<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
  FB.init({
    appId      : '--------------', // App ID
    channelUrl : 'http://www.---------.com/channel.html', // Channel File
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
  });


    FB.Event.subscribe('auth.statusChange', function(response) {
        if(response.status === 'connected')
            {
                console.log('Hello there!');
                addScope();

            }
        else if(response.status === 'not_authorized')
            {
               console.log('not authorized');
                addScope();

            }
        else
            { 
                console.log('not logged in');
                addScope();
            }
    });



  FB.Event.subscribe('auth.authResponseChange', function(response) {
    // Here we specify what we do with the response anytime this event occurs. 
    if (response.status === 'connected') {
      // ...
    } else if (response.status === 'not_authorized') {
      // ...

    } else {
      //...
    }
  });
  };

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


  function addScope()
  {
      FB.login(function(response) {
   if (response.authResponse) {
     console.log('Welcome!  Fetching your information.... ');
     FB.api('/me', function(response) {
       console.log('In addscope function, ' + response.email + response.birthday);
     });
   } else {
     console.log('User cancelled login or did not fully authorize.');
   }
 },{scope: 'email,user_birthday'});

  }
</script>

</body>
</html>
4

3 に答える 3

2

コードで適切なアクセス許可が設定されているかどうかを確認する効果的な方法は、次のコードを使用することです (クエリ部分で確認するフィールドを変更します)。

FB.api({ method: 'fql.query', query: 'SELECT user_status,friends_status,user_photos,friends_photos,user_location,friends_location FROM permissions WHERE uid=me()' }, function(resp) {   
for(var key in resp[0]) {   
    if(resp[0][key] === "1")   
        console.log(key+' is granted');   
    else   
        console.log(key+' is not granted');   
}   
});

ユーザーが電子メール ID にアクセスする権限を与えていない可能性があります。

于 2013-10-18T16:53:43.780 に答える
1

私が見る限り、他の場所でエラーがスローされておらず、「addScope」メソッドが呼び出されていれば、コードは正しいです。返される値が実際にあることを確認してください (ユーザーに誕生日と電子メールがあることを確認してください。そうしないと、値が返されません。ここで説明されているように: https://developers.facebook.com/docs/reference/api/user / )

私は FB API を使用していますが、ユーザー アクセス トークンを使用している間、電子メールやその他のフィールドを取得するのに問題はありませんでした。

于 2013-08-29T14:06:49.643 に答える