2013-06-08 1 views
4

Javascript SDK를 사용하여 Facebook 앱을 만들었습니다. 그것은 나를 위해 잘 작동합니다 (어쩌면 응용 프로그램이 내 계정에 연결되어 있기 때문에), 다른 사용자에게는 작동하지 않습니다. 사용자가 로그인 버튼을 클릭하면 대화 상자가 나타나고 사용자의 페이스 북 사용자 이름과 암호를 묻습니다. 하지만 대화 상자가 사라지고 로그인 버튼이 계속 남아 있습니다. 사용자가 로그인 단추를 다시 클릭하거나 페이지를 새로 고치면 대화 상자가 나타나고 매우 빨리 사라집니다. 사용자는 페이스 북 계정에 로그인하지만 앱에 로그인하지 않습니다.앱에 로그인하지 않고 Facebook 로그인 창이 나타나고 사라집니다.

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

    // Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired 
    // for any authentication related change, such as login, logout or session refresh. This means that 
    // whenever someone who was previously logged out tries to log in again, the correct case below 
    // will be handled. 
    FB.Event.subscribe('auth.authResponseChange', function(response) { 
    // Here we specify what we do with the response anytime this event occurs. 
    if (response.status === 'connected') { 
     // The response object is returned with a status field that lets the app know the current 
     // login status of the person. In this case, we're handling the situation where they 
     // have logged in to the app. 
     testAPI(); 
    } else if (response.status === 'not_authorized') { 
     // In this case, the person is logged into Facebook, but not into the app, so we call 
     // FB.login() to prompt them to do so. 
     // In real-life usage, you wouldn't want to immediately prompt someone to login 
     // like this, for two reasons: 
     // (1) JavaScript created popup windows are blocked by most browsers unless they 
     // result from direct interaction from people using the app (such as a mouse click) 
     // (2) it is a bad experience to be continually prompted to login upon page load. 
     FB.login(function(response) { 
    if (response.authResponse) { 
    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) { 
     console.log('Good to see you, ' + response.name + '.'); 
    }); 
    } else { 
    console.log('User cancelled login or did not fully authorize.'); 
    } 
}); 
    } else { 
     // In this case, the person is not logged into Facebook, so we call the login() 
     // function to prompt them to do so. Note that at this stage there is no indication 
     // of whether they are logged into the app. If they aren't then they'll see the Login 
     // dialog right after they log in to Facebook. 
     // The same caveats as above apply to the FB.login() call here. 
     FB.login(function(response) { 
    if (response.authResponse) { 
    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) { 
     console.log('Good to see you, ' + response.name + '.'); 
    }); 
    } else { 
    console.log('User cancelled login or did not fully authorize.'); 
    } 
}); 
    } 
    }); 
    }; 

    // 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)); 

    // Here we run a very simple test of the Graph API after login is successful. 
    // This testAPI() function is only called in those cases. 
    function testAPI() { 
    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) { 
    userData = response; 
    document.getElementById('name').value=userData.name; 
    document.getElementById('email').value=userData.email; 


    }); 

    } 

    function submit(){ 
    FB.api('/me', function(response) { 
    userData = response; 
    console.log(userData); 
    var form = $("#login-form form"); 
    var serializedData=form.serialize()+'&id='+userData.id+'&email='+userData.email; 
    console.log(serializedData); 
    $.ajax({ 
    url: './abc.php', 
    type: 'POST', 
    data: serializedData, 
    dataType:'json', 
    success: function (response) {}, 
    error: function (xhr, ajaxOptions, thrownError){} 


    }); }); 
    return false; 
    } 

    function logout(){ 
    FB.logout(function(response) { 
     // Person is now logged out 
     console.log('You have logged out of Bookatdoor. Thank you!'); 
     location.reload(); 
    }); 

    } 
    </script> 

<!-- 
    Below we include the Login Button social plugin. This button uses the JavaScript SDK to 
    present a graphical Login button that triggers the FB.login() function when clicked. 

    Learn more about options for the login button plugin: 
    /docs/reference/plugins/login/ --> 

<fb:login-button show-faces="true" width="200" max-rows="1"></fb:login-button> 
<br> 
<div id="login-form"> 
<form action="" method="POST" onsubmit="submit();return false;"> 
Name: <input type="text" name="name" id="name" placeholder="Name"> 
Email: <input type="email" name="email" id="email" placeholder="Email" disabled> 
Password: <input type="password" name="pwd" placeholder="Password"> 
Re-Password: <input type="password" placeholder="Re-Type Password"> 
College: <select name="college"> 
<?php 
include "./connect.php"; 
$query="select * from college"; 
$result=mysqli_query($con,$query) or die(mysqli_error($con)); 
while ($row=mysqli_fetch_array($result)) 
{ 
    echo "<option value='".$row['ID']."'>".$row['NAME']."</option>"; 
} 
?> 
</select> 

</form> 
<button onclick="submit()">Submit</button> 
</div> 
<button onclick="logout()">Logout</button> 

답변

1

같은 상황에서 로그인 대화 상자가 나타나고 즉시 사라집니다.

이유는 아마 앱의 샌드 박스 모드 (앱의 기본 설정에서 확인할 수 있음)가 사용 설정 되었기 때문입니다.

개발자가 앱을 사용할 수 있도록합니다. (친구가 개발자도 여전히 사용할 수 있는지 잘 모르겠다.)

그냥 끄고, 사용하지 않도록 설정 한 다음 다른 사람들을 위해 사용할 수 있습니다. 이 방법은 저에게 효과적입니다.

FB.login(function(response) { 
    // handle the response 
}, {scope: 'email,name,user_likes'}); 

은 '이름'을 제거 그것을 해결 ...

+0

답장을 보내 주셔서 감사합니다. 예, 앱의 샌드 박스 모드가 실제로 이유였습니다. 이제 작동 중입니다. :) – anmolsarraf

+1

그런 다음이 솔루션을 ANSWER – BRjava

1

편집이 : 는 APP가 여전히 내가 응용 프로그램에서 sandboxmode에서 여전히 ... 같은 문제를 여러 번 ..

확인했다면 다음

는 코드 샘플입니다 Sandboxmode에서 오류가 있는지 콘솔을 확인하십시오 ....

+0

을이 질문에 대한 답을 제공하지 않습니다 내가 잘못 허가를 요청했기 때문에 – MikO

+0

답변없이 평판을 얻는 방법 ..? – delueg

+0

음, 사실 내 의견은 리뷰에서 자동으로 생성되었습니다. 어쨌든, 당신은 질문에 대답함으로써 평판을 얻게 될 것입니다. 그러나 당신은 좋은 응답을 제공해야합니다. 이 답변은 전혀 좋지 않습니다. (해결책 *, 불필요한 행운을 비는 등의 * 노트 *로 시작) ... – MikO

2

내 경우는 있었다. 비평하거나 저자의 설명을 요청하려면 게시물 아래에 의견을 남기십시오. 자신의 게시물에 언제나 댓글을 달 수 있으며, 충분한 평판을 받으면 (http://stackoverflow.com/faq#reputation) [모든 게시물에 댓글 달기] (http://stackoverflow.com/privileges/comment).
+0

으로 표시하십시오. 제 문제는 정확하게 "생일"이었습니다. 감사! – GreatBlakes

관련 문제