Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Facebook SDK javascript_Javascript_Facebook_Sdk_Facebook Javascript Sdk - Fatal编程技术网

Facebook SDK javascript

Facebook SDK javascript,javascript,facebook,sdk,facebook-javascript-sdk,Javascript,Facebook,Sdk,Facebook Javascript Sdk,我正在尝试使用以下代码随机获取用户朋友的ID和姓名: // Acess Grantes of permissions code (not full (work)) function checkPerms(){ var permsNeeded = ['email','public_profile','user_friends']; //.... Continue of CheckPerms ( it works fine) // this is User's Friend ID r

我正在尝试使用以下代码随机获取用户朋友的ID和姓名:

 // Acess Grantes of permissions code (not full (work))

function checkPerms(){
    var permsNeeded = ['email','public_profile','user_friends'];
//.... Continue of CheckPerms (  it works fine)

// this is User's Friend ID random ( no work) 
          FB.api(
        "/{user-id}/friends",
        function (response) {
          if (response && !response.error) {
            var random = Math.floor(Math.random()*response.data.length);
            console.log(random);
            /* handle the result */
          }
        }
    );
// this is user NAME (work)
FB.api("/me", function(res){
            uname = (res.name)?res.name : '';
            console.log(uname);
        }); 
// This is User Friend's NAME ( no work)
    FB.api("/"+uid1, function(res){
            fname = (res.name)?res.name : '';
            console.log(fname);
        });

我只得到联塞特派团的安慰,其他人没有。你能告诉我我的代码有什么问题吗/或者我是否需要facebook的任何权限来访问朋友ID和姓名的数据。

由于Graph API的v2.0版,出于隐私原因,你只能访问授权你的应用程序的朋友。用户朋友权限。


在这个线程中有一个关于这个问题的非常详细和完整的答案:

这是我用来保存数据的代码

function GetFBLoginStatus() {
        FB.getLoginStatus(function (response) {
            console.log(response);
            if (response.status === 'connected') {
                var accessToken = response.authResponse.accessToken;
                var email = response.authResponse.accessToken;
                FB.api('/me', { locale: 'en_US', fields: 'id, name, email' },
                    function (response) {
                        console.log(response.id);
                        console.log(response.name);
                        console.log(response.email);
                        alert("Funcion GetFB");

                        var id = document.getElementById("<%=HiddenField1.ClientID%>");
                        var nombreDePersona = document.getElementById("<%=HiddenField2.ClientID%>");
                        var email = document.getElementById("<%=HiddenField3.ClientID%>");

                        id.value = response.id;
                        nombreDePersona.value = response.name;
                        email.value = response.email;

                        __doPostBack("MyCall", "");
                }
            );
        } else if (response.status === 'not_authorized') {
            //login function
            alert('login first');
        } else {
            //login function
            alert('login first');
        }
    }, true);
    }
函数GetFBLoginStatus(){ FB.getLoginStatus(函数(响应){ 控制台日志(响应); 如果(response.status===“已连接”){ var accessToken=response.authResponse.accessToken; var email=response.authResponse.accessToken; api('/me',{locale:'en_US',字段:'id,name,email'}, 功能(响应){ console.log(response.id); console.log(response.name); console.log(response.email); 警报(“函数GetFB”); var id=document.getElementById(“”); var nombreDePersona=document.getElementById(“”); var email=document.getElementById(“”); id.value=response.id; nombreDePersona.value=response.name; email.value=response.email; __doPostBack(“MyCall”和“); } ); }else if(response.status===“未授权”){ //登录功能 警报(“先登录”); }否则{ //登录功能 警报(“先登录”); } },对); }
我调用一个c#方法,并将值传递给隐藏字段。

您只能获得已授予该应用程序用户朋友权限的朋友。不是所有的朋友,怎么才能得到谁不同意的呢?我将允许我这样做。如果它确实需要facebook管理员的审查?你只需要请求授权人我想让一个用户访问他们所有的朋友ID/PIC/姓名,那么这怎么可能呢?你不能。您只能获得已授予权限的朋友