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
Related
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
I am about to finish my cordova application where i am using the facebook social login. I am trying to access the user information from the graph API that openfb.js is calling. My code snippet is this:
function login() {
openFB.login(
function (response) {
if (response.status === 'connected') {
alert(JSON.stringify(response));
FACEBOOK_TOKEN = response.authResponse.accessToken;
var message = "Connected to Facebook_____";
alert('Message is :' + message);
alert('Access token is :' + FACEBOOK_TOKEN);
getInfo(response.authResponse.accessToken);
} else {
var errorMessage = 'Facebook login failed: ' + response.error + "_____";
alert(errorMessage);
}
}, {scope: 'email,public_profile,user_birthday,user_location'});
}
function getInfo(access_token) {
openFB.api({
path: '/2.5/me?access_token=' + access_token,
success: function (data) {
alert(JSON.stringify(data));
var message = "Logged in with Facebook as " + data.name + "_____";
alert(message);
},
error: errorHandler
});
}
function errorHandler(error) {
var errorMessage = error.message;
alert('Error is : '+errorMessage);
}
Here in this case when i am getting the access token of the user but when i pass it to graph API that is in the get info function, then it shows me the error:
Error is : Malformed access token CAANoTLg2W..........
I am not able to debug the error ocuring here. Please help me resolve it.
Thank in advance for any response.
I am developing a facebook app where I need impersonation of users, so there is an option when you use facebook for "Use Facebook As", i need to implement the same in my app.
I see the access tokens retrieved for the pages I own, but I don't understand how to use this with the following graph api to post
var body = 'Reading JS SDK documentation';
FB.api('/me/feed', 'post', { message: body }, function (response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response.id);
}
});
so my question is how do I set the access token for the api in this case??
I Hope, am clear with my question
Add it with the parameters. Change this line
FB.api('/me/feed', 'post', { message: body }, function (response) {
to...
var my_token = "the access token value";
FB.api('/me/feed', 'post', { message: body, access_token : my_token }, function (response) {
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.
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.