Get Facebook user profil link with hello.js - facebook

I'm using hello.js to login and get user information for several social networks and it works.
I now need to get the facebook users profile link, so I asked for the permission(user_link) for my FB app and got it, so now when I log with the app I'm warned that the app will have access to my profile url.
However I don't know how to get this information with hello.js, all I have in the response is :
first_name: "Jerome"
id: "..."
last_name: "..."
name: "..."
picture: "https://graph.facebook.com/.../picture"
thumbnail: "https://graph.facebook.com/.../picture"
this is a part of my code :
var socialnetwork = facebook;
var socialscopes = basic_profile;
hello(socialnetwork).login({scope: socialscopes},function() {
return hello(socialnetwork).api('me').then(function(r) {
console.log(r);
}
A clue ? THX !!!

Related

Sails Rest API using Passport-Facebook-Token Strategy Driving Me Nuts

I have a mobile front-end that already has facebook authetication working. I have a Sails REST API that stores user data, posts etc.. I want to add security where facebook users can only POST GET DELETE PUT their own data.
I've read a almost every tutorial for facebook authenticating a web-app, but haven't found many for authenticating with a mobile app to protect the user data. I've tried to get Passport-Facebook-Token working but I just don't understand the little documentation available. I'm coming from a objective-C background so in the node learning curve now.
Here's the link to what I'm working with but I'm obviously missing something: https://github.com/drudge/passport-facebook-token
I have:
AuthController.js
module.exports = {
facebook: function(req, res) {
passport.authenticate('facebook-token', function(error, user, info) {
// do stuff with user
res.ok();
})(req, res);
}
};
api/services/protocols/passport.js
(with some other stuff from default passport sails-generate-auth)
var FacebookTokenStrategy = require('passport-facebook-token');
passport.use('facebook-token', new FacebookTokenStrategy({
clientID : "<my_id>",
clientSecret : "<my_secret>"
},
function(accessToken, refreshToken, profile, done) {
// console.log(profile);
var user = {
'email': profile.emails[0].value,
'name' : profile.name.givenName + ' ' + profile.name.familyName,
'id' : profile.id,
'token': accessToken
}
// You can perform any necessary actions with your user at this point,
// e.g. internal verification against a users table,
// creating new user entries, etc.
return done(null, user); // the user object we just made gets passed to the route's controller as `req.user`
}
));
Do I have to do something with config/routes to make sure it only allows users with access_tokens? I just can't find any resources out there. Passport doesn't even list Passport-Facebook-Token strategy as an option on their site.
thank you for the help

Grails Spring Security Core - How to display profile picture using Spring Security Facebook plugin?

I am building my first grails app and have successfully integrated all of the following plugins:
Spring Security Core plugin
Facebook Authentication for Spring Security
Spring Security UI plugin
Currently, I can click a "Login with Facebook" button and I've added a FacebookAuthService which allows me to fetch username, e-mail, etc. and I am displaying the username to the screen using the "sec" taglib. My question is regarding how to fetch the user's Facebook Profile Picture and display it to the page. I've looked all over and couldn't find a good example. Can anyone provide one?
I have the following method defined in FacebookAuthService:
FacebookUser create(FacebookAuthToken token) {
log.info("Create domain for facebook user $token.uid")
//Use Spring Social Facebook to load details for current user from Facebook API
Facebook facebook = new FacebookTemplate(token.accessToken.accessToken)
FacebookProfile fbProfile = facebook.userOperations().userProfile
String email = fbProfile.email
String username = fbProfile.username
String firstName = fbProfile.firstName
String lastName = fbProfile.lastName
User person = new User(
username: [firstName, lastName].join(' '),
password: token.accessToken.accessToken, //not really necessary
enabled: true,
accountExpired: false,
accountLocked: false,
passwordExpired: false,
//fill with data loaded from Facebook API
name: [firstName, lastName].join(' '),
email: email
)
person.save( flush : true)
person.validate()
println person.errors
UserRole.create(person, Role.findByAuthority('ROLE_USER'))
UserRole.create(person, Role.findByAuthority('ROLE_FACEBOOK'))
FacebookUser fbUser = new FacebookUser(
uid: token.uid,
accessToken: token.accessToken.accessToken,
accessTokenExpires: token.accessToken.expireAt,
user: person
)
fbUser.save()
return fbUser
}
In my case I needed imageUrl but not image itself
You can use following urls to obtain different sizes of profile images. Please make sure to add Facebook id to url.
Large size photo https://graph.facebook.com/{facebookId}/picture?type=large
Medium size photo https://graph.facebook.com/{facebookId}/picture?type=normal
Small size photo https://graph.facebook.com/{facebookId}/picture?type=small
Square photo https://graph.facebook.com/{facebookId}/picture?type=square
P.s. You can get facebookId from userProfile:
facebook.userOperations().getUserProfile();
I got byte array and saved this as pic.
byte[] profilePic = facebook.userOperations().getUserProfileImage();

Post a message on Facebook using FB.api

I write down a code in javascript for posting message on Face-Book. I posted it successfully but it's always showing only me privacy statement.
I really want to post this message publicly.
I try to set privacy = { 'value': 'EVERYONE' }; . still message posting private(only me).
My code is-
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);
}
});
How can i post it publicly ?
thanks a bunch for your valuable help.
Did you manually set the privacy of the application when you added your application? If you go to your Facebook Settings, see what you set your application to. The privacy parameter is restricted to what the user sets on their account.
E.g. If the user has set "Friends", but the app uses "Public", then the user's preference is used. But if the user has set "Public", but the app uses "Friends", then the app's setting is used, as it's more restrictive than the User's settings.
In short, the most restrictive privacy setting between the User and Application will take priority.

Spotify FB Login with preview api

Anyone knows how the facebook login works with the new preview spotify apps api?
I tried something like this...
require(['$api/facebook'], function(facebook) {
facebook.session.showConnectui();
}
but nothing got me to the result I got with the old api. I also tried to use plain FB js sdk, but the problem is it needs some "url" to allow connections...wich I can't really give out of the spotify app?
Any ideas?
The auth module was not present at first, but now it is part of the Spotify Apps API. You can read more about it on its documentation page. It looks like this:
require(['$api/auth#Auth'], function(Auth) {
var appId = '<your_app_id>',
permissions = ['user_about_me'];
var auth = new Auth();
auth.authenticateWithFacebook(appId, permissions)
.done(function(params) {
if (params.accessToken) {
console.log('Your access token: ' + params.accessToken);
} else {
console.log('No access token returned');
}
}).fail(function(req, error) {
console.error('The Auth request failed with error: ' + error);
});
}
});
In addition, there is a working example in the Tutorial App on GitHub.

Post on Friends' Wall(s) via Facebook Actionscript 3 SDK

I'm absolutely new to programming and just managed to learn the basics of ActionScript 3. Now, I would like to learn how to post on my Friends' Walls via the as3 SDK using the UI class (taken from a nice Tutorial):
This is how I post on my own Wall:
protected function newsFeed ():void
{
// define your caption text
var theCaption:String = "CaptionText";
// define the descrition text
var theDescription:String = "Text for game Achievement";
// We need to follow the FB docs to tell it what sort of input we are sending to FB
// We are trying to set the 'feed'
var methodInput:String = 'feed';
var thePicture:String = "mylink/picture.png";
var theLink:String = "mylink";
var theName:String = "Name of FB Status Setter";
// Create an object that we'll call 'data' and fill it with the actual data we're sending to Facebook
var data:Object = {
caption:theCaption,
description:theDescription,
picture:thePicture,
name:theName,
link:theLink
};
Facebook.ui(methodInput, data, onUICallback);
}
protected function onUICallback(result:Object):void
{
// do something
}
This works perfectly fine. I know that I have to integrate the parameter "to" somewhere. But I don't know where and how. Sorry I'm very very new to this. This is from Facebook Docs
Properties
from: The ID or username of the user posting the message. If this is unspecified, it defaults to the current user. If specified, it must be the ID of the user or of a page >that the user administers.
to: The ID or username of the profile that this story will be published to. If this >is unspecified, it defaults to the the value of from.
Hopefully someone can help me out.
Best Regards,
Amir
P.S.: Is there a way to post only one friend's wall and another way to post on several friends' walls?
I believe you want to use Facebook.api() rather than 'ui'. According to the documentation for the AS3 FB API, 'ui' just opens the share dialog. If you want to create a post on a friends wall, then you'll want to use 'api'.
I haven't tested this in Flash, but I think you can set the method as /PROFILE_ID/feed ... of course replacing "PROFILE_ID" with the FB uid of the friend. Then, include the arguments; message, picture, link, name, caption, description and source in your data object.
So your code would look something like:
var method:String = "/friend_id/feed";
var data:Object = {};
data.message = "Your message";
data.picture = "http://www.google.com/kittens.jpg";
data.link = "http://www.mysite.com/link";
data.caption = "Your caption";
data.description = "Your description";
data.source = "http://www.mysite.com/video.swf";//(optional) source is a video or Flash SWF
Facebook.api(method, yourCallback, data, "POST");
function yourCallback(result:Object, fail:Object):void {
if (result) {
trace(result)
} else if (fail) {
trace(fail);
}
}
If you have multiple friends, you could probably just put the uid's in an array and loop through the method above. The AS3 API has a batch request method that I haven't tried, but you can check out the Documentation.
Facebook has some pretty helpful tools that are somewhat hidden.
Checkout their Debugger and their Graph API Explorer
Hope that's helpful.