Just a short brief:
- In Facebook you cannot develop now with live users. If you want to test something you can create another facebook App and in development mode you can create dummy users.
- Please use this package: “meteor-facebook-login”: “git+https://github.com/activitree/meteor-facebook-login.git”. I revamped another package and details can be found in the git.
- In the Git you will find the exact Cordova plugin you have to use (the “most” official one which includes the latest Facebook Graph SDKs).
- These are very new versions of everything so you will probably need to do a “pod install” for Xcode and see if there are any conflicts of packages in Android.
- Meteor has a “bug” related to the Facebook Cordova plugin and you cannot re-build Meteor Cordova without deleting all plugins. If you work intensively on this I can tell you how to prevent that by altering a line in the Meteor build sequence until the job is done and eventually you can switch back after.
I can be your testing user on mobile if you wish.
Your mobile-config.js needs this:
App.configurePlugin('cordova-plugin-facebook4', {
APP_ID: 'xxxxxxx',
APP_NAME: 'Appname'
})
your startup / server needs this:
import { Meteor } from 'meteor/meteor'
import { ServiceConfiguration } from 'meteor/service-configuration'
import 'meteor-facebook-login'
Meteor.startup(() => {
const services = Meteor.settings.private.oAuth
if (services) {
for (let service in services) {
ServiceConfiguration.configurations.upsert({ service: service }, {
$set: services[service]
})
}
}
})
Your signing function looks like this:
import { FB_API } from 'meteor-facebook-login'
if (Meteor.isCordova) {
FB_API.login(err => {
if (err) {
if (err !== 'User cancelled.') {
toastr.error('Could not sign in', err) --- or your logger on user screen if you use one
console.log(err)
}
/*..... is some other error do ....something else */
} else {
/* maybe direct to a dashboard, feed, or a ... Mongo delete everything ... :) */
}
})
}
Then you will be probably using an onCreate function for new users. Here is an example of getting the avatar:
let avatar = null
let fbi = null
if (fb) {
/**
* I upload to S3 and I don't wait for a response. A little risky...
*/
put_from_url(`https://graph.facebook.com/${fb.id}/picture?width=500&height=500`, `avatar/${fb.id}.jpg`, (err, res) => {
if (err) {
console.log('Could not upload FB photo to S3, ', err)
} else {
console.log(res)
}
})
user.profile = extend(user.profile, {
firstName: fb.first_name,
lastName: fb.last_name,
email: fb.email,
displayName: fb.name,
gender: startCase(toLower(fb.gender)),
avatar: `${fb.id}.jpg`
})
avatar = `${fb.id}.jpg`
fbi = fb.id
}
For the function “put_from_url” you will need to have this after all your imports (and the NPM indeed) or you can choose any other https modality to save it where you want to have it. This is just an example for S3.
const put_from_url = (url, key, callback) => {
request({
url: url,
encoding: null
}, (err, res, body) => {
if (err) {
console.log('Could not request FB or Google photo, ', err)
} else {
s3.putObject({
Bucket: 'your bucket name',
Key: key,
ContentType: res.headers['content-type'],
ContentLength: res.headers['content-length'],
Expires: new Date('2050/12/20'),
CacheControl: 'max-age=8460000',
Body: body // buffer
}, callback)
}
})
}
If you in fact want to save that to S3, I can give you the entire setup and package to do it.
Let me know if and when you need anything.