One benefit of node js that we can use the ready made huge base of javascript libraries? So, I was wondering how to integrate the Facebook sdk at http://connect.facebook.net/en_US/sdk.js into my node project?
I am a bit new to Node so the question might be naive..
You cannot integrate the Facebook SDK directly. There are some libraries at http://npmjs.org which deal with Facebook connectivity, but most of them are quite old.
If you're just looking for Facebook Login integration, https://www.npmjs.org/package/passport-facebook could be a starting point.
I ended up developing my of "library", which is not too complicated because the Facebook Graph API can be used via standard HTTP requests.
Try this .
First do npm install facebook-nodejs-sdk
And then
var connect = require('connect'),
fbsdk = require('facebook-sdk');
connect()
.use(connect.cookieParser())
.use(connect.bodyParser())
.use(fbsdk.facebook({
appId : 'YOUR APP ID',
secret : 'YOUR API SECRET'
}))
.use(function(req, res, next) {
if (req.facebook.getSession()) {
res.end('Logout');
// get my graph api information
req.facebook.api('/profile', function(me) {
console.log(me);
});
} else {
res.end('Login');
}
})
.listen(9000);
Related
I am attempting to use the snapkit login web api for a hybrid application. I have successfully been able to intercept the access token in the redirectURL. I was wondering if there was a way to get the users Bitmoji using this access_token and either the functions found in login.js or an http get call?
Api docs: https://docs.snapchat.com/docs/login-kit/#web
currently I have the access_token in a deeplinking function on my app.component.ts . I have attempted to push to a new page with the navController and passing in the access_token as a parameter, but this doesn't help when attempting to get the users information.
Thanks in advance for your help.
Here is the Deeplinking where I intercept the access_token using myapp://settings-set/ as the URL redirect and attempt to push a new page with the matching url.
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
statusBar.styleDefault();
splashScreen.hide();
this.deeplinks.routeWithNavController(this.nav,{
'/settings-set/:token': SettingsSetPage
}).subscribe((match) => {
// match.$route - the route we matched, which is the matched entry from the arguments to route()
// match.$args - the args passed in the link
// match.$link - the full link data
this.nav.push(SettingsSetPage, {
args: match
});
console.log('Successfully matched route', match.$args);
},
(nomatch) => {
// nomatch.$link - the full link data
console.error('Got a deeplink that didn\'t match', nomatch);
});
});
}
In the setting-set page I recieve the parameter using:
this.args = navParams.get('args');
console.log("this is args", JSON.stringify(this.args));
but don't know how to use the information to get the users information
The Bitmoji API can be very confusing at times. I suggest using Passport, a Node JS tool for OAuth, along with the Ionic framework. Snapchat has a guide that explains how to grab specific fields, such as user name and Bitmoji avatar, from a user's Snapchat profile using passport. You can follow this tutorial to learn how to integrate Node JS into your existing ionic app.
So in conclusion, try following these steps:
Integrate Node JS into your existing ionic app
Install Passport and follow Snapchat's guide for obtaining specific fields from the user's profile
Yes, like Mora said you can use passport which will make your life easier. We also have a sample passport app running here:
From the context you provided it seems like you have generated the code and not the access_token. After you get the code from the redirect url, you need to use the code to generate the access token. Check section 2.5 here.
Once you have the access token you can use that to request information. The crux of this lies in setting the "scope" correctly. To get the Bitmoji avatar make sure you set your scope to this at the very least:
var scope = ['https://auth.snapchat.com/oauth2/api/user.bitmoji.avatar'];
Hope this helps!
I am using cordova in my ionic app. For the Facebook functionality I am getting that "currently uses Facebook SDK for iOS v4.15.1, which relies on the recently deprecated Version 2.7 of the Graph API.
As a result, there is a risk that your app will no longer function if you don't upgrade to Facebook SDK for iOS v4.39.0.
As an admin of this app, please upgrade to the latest SDK as soon as possible to ensure your app's continued performance and to take advantage of new features."
But I am not using Facebook SDK, I am using openfb.js to login the user into the app.
Please confirm how I need to make sure that my app will run smoothly as I am not using this Faceboook SDK.
Here is the code which I am using in my App to use the Facebook functionality:
Also the reference link for OpenFB : https://github.com/ccoenraets/OpenFB
$scope.fbLogin = function(){openFB.init({appId: 'XXXXXXXXXXXXXX'});
openFB.login(
function(result1) {
if(result1.status === 'connected') {
var access_token = result1.authResponse.accessToken;
openFB.api({
path: '/me',
success: function(result) {
var o = {};
o.id=result.id;
o.email = result.email;
o.first_name = result.first_name;
o.last_name = result.last_name;
o.gender = result.gender;
o.name = result.name;
//Hitting some api to get the data
console.log(JSON.stringify(result));
},
error: errorHandler});
} else {
console.log(JSON.stringify(result1));
}
}, {scope: 'publish_actions, email, public_profile, user_friends'});
}
Facebook link share count API
https://graph.facebook.com/?id=http://stackoverflow.com <--- v1.0 (current.. available)
but
is this available after version 2.x? (without access token)
I want use this API
reference
https://developers.facebook.com/docs/graph-api/reference/v2.1/url
Nobody can look into the future, but I doubt facebook will disable that endpoint again so soon, because the "new version" was only introduced with v2.1.
The docs at https://developers.facebook.com/docs/graph-api/reference/v2.2/url state that an Access Token is required for the usage of this endpoint. This means you can also use an App Access Token, which is easy to get. Just create a new app at https://developers.facebook.com/apps/ and you're ready to go.
I have the same issue. And after some research I find this link https://developers.facebook.com/blog/post/2009/10/26/extending-facebook-share/ .
You can try use this approach, it work with any version FB API:
FB.api({
method: 'links.getStats',
urls: 'here you url'
}, function(response){
alert(response[0].total_count)
});
or https://api.facebook.com/restserver.php?&method=links.getStats&urls=http://stackoverflow.com&format=json-strings
I'm using phonegap 3.5.0-0.20.4 & wp8 platform. My FB.login call simply doesn't seem to do anything (no response). I checked other replies around similar problem, but none seem to help wp8 platform. Here is my sample code
FB.init({appId: "23...32", version: 'v2.0'});
FB.login(function (response) {
console.log(JSON.stringify(response);
}, { scope: "email" });
My login call simply doesn't go through. I do have webbrowser & device plugins installed on the phonegap app.
Any ideas?
There are deprecated documentation, try this
FB.login(['public_profile'], successCallbackFn, errorCallbackFn);
But this has no sense because facebook does not return callback functions on login after april's sdk update to version 3.14
Please let me know if facebook login will work for you.
I recently integrated the phonegap-facebook-plugin (https://github.com/phonegap/phonegap-facebook-plugin) into both iOS and Android (same app).
I want to do something that I believe to be simple: by-pass the call to native facebook for login/authentication and always use the web dialog. How does one go about accomplishing this?
My login code currently looks like this:
Init code:
//facebook initialization
FB.init({
appId: 'xxxxxxxxxxxx', //'<%#= FB_APP_ID %>',//'',
nativeInterface: CDV.FB,
useCachedDialogs: false
});
And the login call is:
FB.login(function(response) {
if (response.authResponse) {
// connected
me.signInFacebook({
token: response.authResponse.accessToken,
email: response.authResponse.email,
success: function (data) {
// hide login view and show tabview
form.destroy();
// continue whatever action was previously happening
me.continueAction(tabIndexBack, callback);
},
failure: function (response) {
// show errors Ext.Viewport.down('tabscontainerview').setActiveItem(3);
}
});
} else {
//go back
Ext.Viewport.down('tabscontainerview').setActiveItem(3);
alert('fb login error');
}
},{ scope: "email" });
Thanks for your help!!
I created a plugin to facilitate the connection between Facebook and phonegap without using Plugin Native only with Jquery:
https://github.com/studiosoton/faceGap
To bypass native FB login, you can make your own manual facebook authentication flow without using JavaScript SDK of the Facebook (https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.3) via inAppBrowser or ChildBrowser plugins.
Your app must initiate a redirect to an endpoint which will display the login dialog:
https://www.facebook.com/dialog/oauth?client_id={app-id}&redirect_uri={redirect-uri}&response_type=token&scope=email
Facebook redirects people to the redirect_uri mentioned above and places an access token along with some other metadata (such as token expiry time) in the URI fragment:
https://www.facebook.com/connect/login_success.html#
access_token=ACCESS_TOKEN...
Your app needs to detect this redirect and then read the access token out of the URI. You can then skip straight to the Inspecting access tokens step.
On the Android version of the plugin, you can force it to use the dialog by modifying the way the plugin calls me.facebook.authorize in the login action of theorg.apache.cordova.facebook.ConnectPlugin class.
You'll need to pass in an additional activityCode parameter with Facebook.FORCE_DIALOG_AUTH:
me.facebook.authorize(cordova.getActivity(), me.permissions, Facebook.FORCE_DIALOG_AUTH, new AuthorizeListener(me));
I'm not entirely sure about iOS, but you might be able to try with openWithBehavior and FBSessionLoginBehaviorForcingWebView
Without any Facebook plugins you can use Facebook functionality,for that use phonegap.facebook.inappbrowser.js using this js you can easily access all Facebook functionality for more information visit this URL : Facebook Integration Step without any plugins