$cordovaOauth facebook getting strange error meassage - facebook

This is my function that I get the profile info of user:
function facebookLogin() {
return $q(function(resolve, reject) {
$cordovaOauth.facebook('CLIENT_ID', ['id', 'email', 'name', 'age_range', 'gender', 'user_photos', 'user_work_history', 'user_friends']).then(function(result) {
$localStorage.facebookToken = result.access_token
$http.get('https://graph.facebook.com/v2.8/me', { params: { access_token: $localStorage.accessToken, fields: 'id, name, email, gender, picture', format: "json" } }).then(function(profile) {
alert(JSON.stringify(profile.data))
resolve(true)
}, function(err) {
console.log(err)
})
}, function(err) {
alert('Erro login: ' + JSON.stringify(err))
})
})
}
In the first function facebook, facebook renders a window and then the user logs in, but I always get this screen, it says: 'Something went wrong, We're working to fix this as soon as possible':
If I i quit this window then the catch error is called and I get "The sign flow was canceled", any ideas?

It was a problem with permissions when i call facebook screen

Related

Get email from facebook respond Could not get resource

I use hello for oauth with facebook.
Login is ok, but no data is returned by Facebook. The message is :
Whoops! Could not get resource
hello.init({
xxxxxxxxxxxxxxxxxxxxxxxxx
},{ scope: 'email', redirect_uri: RacineSite() });
hello(type).login({ scope: 'email' });
hello.on('auth.login', function (auth) {
if (type == auth.network) {
hello(type).api('me').then(function (json) {
alert('Your name is ' + json.email);
}, function (e) {
alert('Whoops! ' + e.error.message);
});
}
});
if type = google, its work fine, but with facebook, no email is returned

Getting all Pages user is Admin of using Graph API

I am trying to get a list of all the pages the logged user an Admin of, but I am getting the error "An active access token must be used to query information about the current user". Here is the code I am using:
function login(){
FB.login(function(response) {
if (response.authResponse) {
$.get("https://graph.facebook.com/me/accounts", function(data) {
alert( "success" );
})
.done(function() {
alert( "second success" );
})
.fail(function(data) {
alert( "error" );
})
.always(function() {
alert( "finished" );
});
} else {
// not auth / cancelled the login!
}
}, { scope: "manage_pages" });
}
So in this code, after logging in, the call $.get("https://graph.facebook.com/me/accounts") throws the error.
UPDATE:
I am able to get the the list using FB.api("/me/accounts"). So how come I can't get it using this code? What am I doing wrong? Thanks.
Simple: You are not passing a user access token with your direct request:
$.get("https://graph.facebook.com/me/accounts", function(data) { ... });
instead of
var accessToken = "aoidhfgoafhgoidfhg"; // replace with real access token
$.get("https://graph.facebook.com/me/accounts?access_token=" + accessToken, function(data) { ... });
The FB SDK does this internally/automatically. What's not really clear to me is why you don't use the FB SDK here as well, if you're already using it for FB Login. That doesn't make much sense IMHO.

Post a public message in Facebook with FB.api

I have tried to post a message on my wall using FB.api(). I posted it successfully but it's showing only for me. I want to make this post public.
In app Configuring permissions i set "Default Activity Privacy" value Public but still message posting private.
I tried to do it by following code:
FB.login(function (response) {
if (response.authResponse) {
var privacy = { 'value': 'EVERYONE' };
var txt = 'my post to test feed post using api';
FB.api('me/feed', 'post', { message: txt, privacy: privacy }, function (response) {
if (!response || response.error) {
alert(JSON.stringify(response.error));
} else {
alert('Post ID: ' + response.id);
}
});
}
}, { scope: 'email,user_likes,publish_actions,publish_stream,read_stream' });
Please check my code.
As said in reference 'privacy' field value should be string.
Try to pass "{ 'value': 'EVERYONE' }" as string, not an object.

Facebook Graph API - Error on success?

I am using the Facebook Javascript SDK to upload a photo to the user's timeline. This is my call:
function post_photo_to_facebook() {
var file_name = 'https://my-image.url.com/image.jpg';
var access_token = FB.getAuthResponse()['accessToken'];
$.ajax({
type: "POST",
url: "https://graph.facebook.com/me/photos",
data: {
message: "Here is my message",
url: file_name,
access_token: access_token,
format: "json"
},
success: function(data){
alert("POST SUCCESSFUL");
},
error: function(data){
alert('Error');
console.log(data);
}
});
}
When in Chrome, I am receiving an Error back from this AJAX call, yet the statusText is "OK", and the image is being successfully uploaded to my timeline. I am just wondering what I am missing here - why is the error being called?
You should be using FB.api to upload images, rather than ajax POST due to CORS reasons.
So your code above would look like this:
var file_name = 'https://my-image.url.com/image.jpg';
FB.api('/me/photos', 'post', {
message:'Here is my message',
url:file_name
}, function(response){
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
and you use FB.init to set up your tokens etc.

Check if Facebook JS-API app already has been given permission

I have a small script that unlocks some content on a page when a user logs in via Facebook and posts some information on their wall.
I want to avoid any duplicate posts (spam) in the event the user visits the page a second time and repeats the process.
Is there a way of (when asking for the permissions) to tell if they have already been given and therefore skip the sharing part of the script?
Here's my code:
$('.preview a').click(function(e) {
e.preventDefault();
FB.login(function(response) {
if (response.session) {
FB.api('/me/feed', 'post', {
message: 'Just unlocked the exclusive preview of...',
picture: 'http://website.com/share.png',
link: 'http://www.website.com',
name: 'Name goes here',
description: 'Description here'
},
function(response) {
if (!response || response.error) {
alert(response.error);
} else {
$('.preview').hide();
$('.clip').show();
}
});
}
},
{perms:'read_stream,publish_stream'});
});
From 2011 to 2014 a lot of things change..
I made this solution to check for "user_friends" and "publish_actions" permissions, if not allowed the both, force the user to "re-autenticate". The callback method will only be called when all permissions are given.
function login(cb,forceAuth) {
FB.getLoginStatus(function (response) {
if (response.status !== 'connected' || forceAuth==true){
FB.login(function (response) {
checkPermissions(cb,false);
}, {scope: 'publish_actions,user_friends'});
} else {
checkPermissions(cb);
}
});
}
function checkPermissions(cb,forceAuth){
FB.api(
"/me/permissions",
function (response) {
if (response.data[0]['publish_actions']==undefined || response.data[0]['publish_actions']==0 ||
response.data[0]['user_friends']==undefined || response.data[0]['user_friends']==0) {
if (forceAuth!=false)
login(cb,true);
} else {
cb();
}
}
);
}
How to use:
login(function () {
myLogedAndAllowedFunction();
});
I've written a tutorial about this here, and here's an example:
FB.api({ method: 'fql.query', query: 'SELECT read_stream,offline_access,publish_stream FROM permissions WHERE uid=me()' }, function(resp) {
for(var key in resp[0]) {
if(resp[0][key] === "1")
console.log(key+' is granted')
else
console.log(key+' is not granted')
}
});
There's also a JS REST example there in the article just for reference.