-1

重複の可能性:
Facebook の友達のメールを取得するには?

私のアプリケーションでは、ユーザーの友達のメール アドレスを取得する必要があります。次のコードを試しましたが、友達のメール アドレスを取得できませんでした。

私のコード:

<div id="fb-root"></div> 
            <script> 
            window.fbAsyncInit = function() {
                FB.init({
                  appId  : 'xxxxxxxxxxxxxxx',
                  status : true, // check login status
                  cookie : true, // enable cookies to allow the server to access the session
                  xfbml  : true,  // parse XFBML
          oauth  :true
                });

  function login(){


        /* Show User's Name*/ 


        FB.api('/me/friends', function(response) {
            alert("user name:"+response.name);
            alert("user mailid:"+response.email);
           // document.getElementById('login').style.display = "block";
           // document.getElementById('login').innerHTML = response.name + " succsessfully logged in!";
        });


    //window.location="http://google.com"; // Redirect to Another Page.

    }

しかし、アラートにはメールIDが表示されていません。これをグーグルで調べたところ、メールは公共の財産ではないことがわかりました。そのため、メールIDを取得するために何ができますか。

4

2 に答える 2

2

私の知る限り、友人のメールアドレスにはアクセスできません。

ありがとうカウシク

于 2012-10-18T05:10:06.980 に答える
1

まず、以下のように FB Javascript SDK を初期化します。

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID from the App Dashboard
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
      status     : true, // check the login status upon init?
      cookie     : true, // set sessions cookies to allow your server to access the session?
      xfbml      : true  // parse XFBML tags on this page?
    });

    // Additional initialization code such as adding Event Listeners goes here

  };

  // Load the SDK's source 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));
</script>

上記のコードは、FB SDK を初期化します。JavaScriptで次の関数を記述します。詳細については、このドキュメントを参照してください。

function initiateFB Login()
{
 FB.login(function(response) {
   if (response.authResponse) 
   {
     //Login Success if you want you can initiate request for friend list here only.
     FB.api('/me/friends/fields=id,username', function(resp)
     {
       /// Process the resp over here. This resp will be JSON response of friend request
     }
     );
   }
   else 
   {
     console.log('User cancelled login or did not fully authorize.');
   }
 });

}

ユーザー名、つまり FB ユーザー名を取得できます。以下、そのお願いです。

me/friends?fields=id,username

このリクエストは、次の形式の JSON レスポンスを返します。

{
  "data": [
    {
      "id": "FB_ID", 
      "username": "FB_USER_NAME"
    }, 
    {
      "id": "FB_ID", 
      "username": "FB_USER_NAME"
    }
]
}

これを解析してユーザー名を取得できます。

お役に立てれば。

ありがとう

カウシク

于 2012-10-18T06:48:28.857 に答える