facebook app not redirecting when aurizing - facebook

When I first authorize a user it goes and stays on the Canvas URL(my site) instead of redirecting back to the Canvas Page on facebook.How can I make sure once the user authorizes they go to the Canvas Page?
$(function() {
FB.init({ appId: 'myappid', status: true, cookie: true, xfbml: true, oauth: true });
FB.getLoginStatus(function(response){
if(!response.authResponse){
top.location.href="http://www.facebook.com/dialog/oauth?client_id=myid&redirect_uri=http://mysite/myapp"
}else{
FB.api('/me',function(response){
uname = response.name;
userid = response.id;
$.post("signin.php", { name:uname,id:userid},
function(data) {
});
});
}
});
});

In your code, change the redirect_uri value from: http://mysite/myapp to: http://apps.facebook.com/appnamespace

Related

Send method of FB.ui does not show multiple recipients

I created an app in Facebook app center and wanted to use this code for sending a message to multiple users. I checked my code in Javascript test console and worked properly but when pasted in my page it just showed the first recipient.
<script>
var arr = [];
arr.push(4);
arr.push(5);
FB.getLoginStatus(function (response) {
FB.ui(
{
method: 'send',
to: arr ,
link: "http://en.wikipedia.org/wiki/Apadana",
picture: "http://upload.wikimedia.org/wikipedia/commons/thumb/5/55/Takhteh_Jamshid.jpg/200px-Takhteh_Jamshid.jpg",
description:"test me",
display: 'iframe'
},
function (param) {
if (!param.success){
// do smthing
}
else{
//throw Err
}
});
});
And also I initiated by these paramethers:
appid = '370960029693800';
channelurl = 'localhost';
window.fbAsyncInit = function () {
FB.init({
appId: appid,
channelUrl: channelurl,
status: true,
cookie: true,
xfbml: true
});
As I said it works in javascript test console and seems something is wrong in initialization part. Please advise me which part of codes is wrong.

FB login dialog opening multiple times, not redirecting

i am having problem with strange behaviour of login dialog. The login dialog is opening multiple times, not closing... at the end after a while it's logging the user in. Seems like some problem with redirecting. I think everything was wroking befor rolling out "february breaking changes". Can you see something from the url, which is passed?? Many thanks for any help!
https://www.facebook.com/dialog/oauth?display=popup&domain=dueto.cz&scope=user_about_me%2Cemail%2Cuser_birthday%2Cpublish_stream%2Cuser_location%2Cuser_hometown%2Cuser_interests%2Cuser_photos%2Cuser_relationship_details&e2e=%7B%7D&app_id=179556678746099&locale=cs_CZ&sdk=joey&access_token=CAACjTkwNvZCMBAMkpzAHCEaGhwGngbNgm6ZB96dDkHNj3yIPy5ZA1qJxaKkkQMrYe8KDD0RUZAg8Tr4yyJRBaiZBgH4PJzQFIPJZC9uZBZCW9ZBuTkkjnHFBC4M3p5MMQZAZAbtGDGn9E5FC0XTLtLEDtbGcl2OSllOnZA2AFlFV4JqVZBwZDZD&client_id=179556678746099&redirect_uri=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D24%23cb%3Df3a7aa399%26origin%3Dhttp%253A%252F%252Fdueto.cz%252Fffe4e034%26domain%3Ddueto.cz%26relation%3Dopener%26frame%3Df2e889c508&origin=1&response_type=token%2Csigned_request
<script>
FB.init({ appId: '<?php echo $this->facebook->getAppId(); ?>', status: true, cookie: true, xfbml: true, oauth: true });
FB.Event.subscribe('auth.login', function(response) { facebookLogin('<?php echo $this->web_url; ?>', '', response); });
FB.getLoginStatus(function(response) { if (response.authResponse.userId) { $.get('/author/canfblogin', {id: response.authResponse.userId}, function(data, textStatus) { if(data.isOk == true) { facebookLogin('<?php echo $this->web_url; ?>', '', response); } }, 'json'); } });
</script>

Cordova Facebook Connect - can't get userID

I added to phonegap app Facebook Connect,
It works fine and generates Access Token, But when I'm trying to get the userID the value is
"Undenified"
my function:
FB.init({
appId: "************",
nativeInterface:CDV.FB,
xfbml: true,
useCachedDialogs: false,
status: true,
cookie: true,
oauth: true
});
//alert("Init Done");
FB.getLoginStatus(function (response) {
if (response.authResponse) {
if (response.status == 'connected') {
Token = response.authResponse.accessToken;// This one is Good!
userid = response.authResponse.userID;// This one is Bad
}
I use the following and it works fine:
FB.api('/me', {}, function (response) {
fbuserid = response.userid;
});
This gives you the user data. You can also pass the scope just to get what you want like email, userid, etc...
Iterate through the keys to see what is stored
for (var key in response.authResponse) {
console.log(key);
console.log(response.authResponse[key]);
}

Facebook FB.ui oauth dialog error

I'm having problems making a dialog box to ask for a user to log into my facebook tab to enter a contest.
We're trying to use the FB.ui oauth dialog box with the following code.
FB.ui({
client_id: '12345',
method: 'oauth',
scope: 'email,user_birthday',
response_type: 'token',
redirect_uri: "https://mydomain.com/test.php" // Change this to proper address
});
When we include the redirect_uri we get the following message
API Error Code: 100 API
Error Description: Invalid parameter
Error Message: The "redirect_uri" parameter cannot be used in conjunction
with the "next" parameter, which is deprecated.
We are not using the next parameter anywhere though, so not sure why it is saying that.
When we take away the redirect_uri we get the following message.
API Error Code: 191 API
Error Description: The specified URL is not owned by the application
Error Message: redirect_uri is not owned by the application.
I would use the FB.login method as opposed to this given you are operating within a tab application.
Within your FB.init:
window.fbAsyncInit = function(){
FB.init({
appId: 'your_app_id',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
FB.Canvas.setAutoGrow(true);
};
FB.getLoginStatus(function(response){
if(response.status == 'connected'){
callyourfunctiontoentercompetition();
}else{
FB.login(function(response){
if(response.status == 'connected'){
callyourfunctiontoentercompetition();
}else{
handlethecancelpermissions();
}
});
}
});
Turns out there was a few things wrong, In my app settings I had to select "Website" and put in my site's URL, this allowed me to add the "app domain" and save it. This cleared up the 191 Error. Having website not checked off your App Domain will not save. After that it was rather simple.
Here the code that I used.
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YOUR_ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
channelURL : 'http://www.your_domain.ca/channel.html', // channel.html file
oauth : true // enable OAuth 2.0
});
// This should be fired on a user initiated action
FB.ui({ method: 'oauth', perms: 'email' }, function() { callback() });
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
function callback() {
FB.getLoginStatus(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
//Get user information from here
});
}
});
}
</script>
make sure the request that u r making is coming from the same domain as the one you have registered in facebook api
In a tab you don't need to pass any parameter other than method and perms(or scope when Facebook changes it)
FB.getLoginStatus(function(response){
if(response.status == 'connected'){
alert("User connected");
}else{
FB.ui({
method: 'oauth',
perms: 'email,user_birthday' //change perms to scope when Facebook supports it
}, function(response){
if(response.session){
alert("User connected");
}else if(response.installed != '1'){
alert("User canceled");
}
});
}
}
)

Can I require FBConnect with the new Graph API?

I'm using the new JS SDK API. (Graph API)
However, if I include the FeatureLoader.js for old FBCOnnect, then it will overwrite the graph API functions..
so, is there anyway in new JS SDK that I can do requireFeatures(['Connect'] ...) as in
FB.Bootstrap.requireFeatures(["Connect"], function()
{
}
No. None of that stuff is needed or supported in the new SDK. All you need to do is initialize the Javascript SDK and call the login method to login.
An example of how to do login:
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: 'your app id', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.sessionChange', function(response) {
if (response.session) {
// A user has logged in, and a new cookie has been saved
} else {
// The user has logged out, and the cookie has been cleared
}
});
$('#loginbutton').click(function() {
FB.login(function(response) {
if (response.session) {
// user successfully logged in
} else {
// user cancelled login
}
});
});
</script>