Facebook API simple authorization failing javascript
I have th开发者_运维百科e following in my source code. I get the alert "No Response" and then the facebook page says "An error occurred with MYAPP. Please try again later"
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js" charset="utf-8"></script>
<script>
FB.init({appId: 'MYAPPID',status: true, cookie:true, xfbml: true});
</script>
<script>
FB.getLoginStatus(function(response){
if(!response.session){
alert("NO RESPONSE");
top.location.href="http://www.facebook.com/dialog/oauth?client_id=MYAPPID&redirect_uri=http://MYWEBSITE";
}
});
Can't see where/if I have gone wrong here.
Thanks
I am getting now the following error:
API Error Code: 191
API Error Description: The specified URL is not owned by the application
Error Message: Invalid redirect_uri: Given URL is not allowed by the Application configuration.
You are using older login code. For FB.init, you should be setting oauth: true
and you will want to check response.authResponse instead of response.session.
<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({ appId: 'MYAPPID', status: true, cookie: true, xfbml: true, oauth: true });
FB.getLoginStatus(function(response){
if(!response.authResponse){
alert("NO RESPONSE");
top.location.href="http://www.facebook.com/dialog/oauth?client_id=MYAPPID&redirect_uri=http://MYWEBSITE";
}
});
</script>
</body>
</html>
精彩评论