Facebook Login fails to build - facebook

I'm developing an App which requires facebook login. The app could build easily when I didn't had implemented the facebook login.
After implementing it, the app cannot build and it doesn't give me a clear error.
I've already added the facebook plugin "Facebook Connect" to my project.
Here's my code:
if(window.navigator.onLine)
{
setTimeout(function(){
var fbLoginSuccess = function (userData) {
console.log("UserInfo: ", userData);
}
facebookConnectPlugin.login(["public_profile"], fbLoginSuccess,
function loginError (error) {
console.error(error)
}
);
},500);
}
On the plugin I already set the correct AppId and AppName.
When I try to test, by building it, nothing happens. It gives me an error when I try to upload it. But it doesn't say cleary what is the error.

you can try read more here
facebookConnectPlugin.login( ["public_profile","email"],function (response) {
if(response.authResponse.userID!=''){
facebookConnectPlugin.api(response.authResponse.userID+"/?fields=id,email,first_name", ["public_profile"],
function (response) {
console.log(response);
},
function (response) {
console.log(response);
});
}
},
function (response) {
console.log(response);
});
let me know if its not working

Related

Apache Cordova Facebook Plugin login not alerting details (not logging in?)

I'm using cordova phonegap and the phonegap-facebook-plugin to login people to my app using facebook. When I use this documentation I don't get what I think should be the expected behavior.
What I'm doing:
I add to my ondevicereadyevent this code:
document.addEventListener('deviceready', initApp, false);
// facebookConnectPlugin.login(Array strings of permissions, Function success, Function failure)
var fbLoginSuccess = function (userData)
{
alert("UserInfo: " + JSON.stringify(userData));
}
function initApp()
{
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
}
But, when I do that and I launch the app on my iPhone, it displays no alerts or prompts to login to facebook.
Also, I tried using this documentation
I add the following code to my ondevicereadyevent
var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
}
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
But again, when I launch the app, there are no alerts or prompts to login to facebook.
When I add alerts as below, only hello1, hello2, and hello2.1 pop up
onDeviceReady: function() {
alert("hello1");
app.receivedEvent('deviceready');
var response;
alert("hello2");
document.addEventListener('deviceready', initApp, false);
alert("hello3");
// facebookConnectPlugin.login(Array strings of permissions, Function success, Function failure)
var fbLoginSuccess = function (userData)
{
alert("UserInfo: " + JSON.stringify(userData));
facebookConnectPlugin.getAccessToken(function(token)
{
alert("Token: " + token);
}, function(err) {
alert("Could not get access token: " + err);
});
}
alert("hello4");
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
alert("hello5");
function initApp()
{
alert("hello2.1");
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
alert("hello2.2");
}
},
Some points:
Before you install a plugin, read the official documentation, read the blogpost and read the issues on github.
The most plugins are third party. That means, it is possible that they don't work, a lot of them are old, …
If you read the official blogpost from Cordova here:
http://cordova.apache.org/announcements/2015/12/08/cordova-ios-4.0.0.html
and you read the issues for your plugin here:
https://github.com/Wizcorp/phonegap-facebook-plugin/issues/1199
Then you now, that the plugin will not work on Cordova versions newer then 8. of dec. 2015
What you can do is: Install an older version of cordova, that means in your case, something lower then 4. How to do it, you can read here:
https://cordova.apache.org/docs/en/dev/platform_plugin_versioning_ref/index.html

facebook connect Phonegap api

I'm having a issue with accessing the Facebook connect Graph API, I have used this plugin, the login example works great and share example also works fine.
I have a problem getting a response from the Facebook API to work.
$(document).ready(function() {
$("#fb_info").click(function() {
facebookConnectPlugin.api("/me",
function (response) {
if (response && !response.error) {
alert(response);
}
}
);
});
});

Facebook share callback, more data?

I'm using a simple Facebook share dialog:
FB.ui(
{
method: 'share',
href: 'http://example.com'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.'+JSON.stringify(response));
} else {
alert('Post was not published.'+linkToShare);
}
}
);
When I get a success callback, all it gives me is the post id. Is there a way to get more data?
What I really want to know is how the page was shared e.g. Only Me, Friends or Public
Is this data out there anywhere?
If you want to know more, you need to use OAuth to get information about the web app using user.
Example:
FB.api('/me', function(response) {
console.log(response);
});
EDIT: Here you can find out more about to get information from a single post

Canvas -> Base64 post to Facebook

I have implemented a pure javascript function for sharing canvas content to an user's facebook wall. The implementation works, but the problem is:
Facebook does not approve the app, stating after review:
"publish_actions on Web - Your app's users must enter all content
in the user message field. Don't auto-populate the message field with
any content, including links and hashtags, even if you allow users to
edit the content before sharing. Watch this informational video for
more information, and see Platform Policy 2.3"
Afaik, there is no way to pass a base64 object through the FB.ui feed share dialogue with client side javascript only.
Question: Any workarounds or other ways go get a client side only canvas -> facebook share implementation that is passed by the Facebook app approval process?
The current implementation is as follows:
document.getElementById('facebook-link').onclick=function(){
FB.login(function (response) {
if (response.authResponse) {
window.authToken = response.authResponse.accessToken;
PostImageToFacebook(window.authToken);
} else {
}
}, {
scope: 'publish_actions'
});
};
function PostImageToFacebook(authToken) {
var imageData = canvas.toDataURL("image/png");
try {
blob = dataURItoBlob(imageData);
}
catch (e)
{
console.log(e);
}
var fd = new FormData();
fd.append("access_token", authToken);
fd.append("source", blob);
try {
$.ajax({
url: "https://graph.facebook.com/me/photos?access_token=" + authToken,
type: "POST",
data: fd,
processData: false,
contentType: false,
cache: false,
success: function (data) {
console.log("success " + data);
},
error: function (shr, status, data) {
alert.log("error " + data + " Status " + shr.status);
},
complete: function () {
console.log("Posted to facebook");
$('#facebook-link').text('Ferdig delt :)').removeClass( "inProgress" );
}
});
} catch (e) {
console.log(e);
}
}
The implementation does not append any text, making me wonder why it does not comply with the Facebook Platform Policy section 2.3.
I had the same problem in an application. Although we have chosen to use the database, I believe it has a solution to your problem.
Really has no way to share a Base64 code by FB.Ui
But as the policies of Facebook, you are not required to use it.
You can create a custom dialog window for the user to view the image that is being posted and enter/confirm the message, and posting after this action.
As the explanatory video from Facebook, the message posted by the user can not be changed, then it should be approved without problems.

Emberjs: check if user is logged with facebook on init

I'm trying to use Facebook to log in an Ember application. The login action is working, but I can't find how to check if the user has already logged in when the app is initialized.
I'm calling the auth.authResponseChange event but it blocks the app and it never starts.
App.ApplicationController = Ember.Controller.extend({
fbUser: false,
init: function() {
this.checkFBUser()
},
checkFBUser: function() {
FB.Event.subscribe('auth.authResponseChange', function(response) {
// this is never triggered and the app does not init
console.log(response)
if (response.status === 'connected') {
console.log('Logged in')
}
else {
FB.login()
}
})
},
// this works
actions: {
loginFacebook: function() {
var self = this
FB.login(function(response) {
if (response.authResponse) {
FB.api('/me', function(response) {
self.set('fbUser', response)
})
}
})
}
}
})
How am I supposed to do this?
I haven't worked with FB lately, but I'm pretty sure the AuthResponeChange event is for being notified of a change in the AuthResponse status; in this instance you'll probably want to take a look at FB.getLoginStatus instead.
https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus
checkFBUser: function()
{
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
// the user is logged in and has authenticated your
// app, and response.authResponse supplies
// the user's ID, a valid access token, a signed
// request, and the time the access token
// and signed request each expire
var uid = response.authResponse.userID;
var accessToken = response.authResponse.accessToken;
} else if (response.status === 'not_authorized') {
// the user is logged in to Facebook,
// but has not authenticated your app
} else {
// the user isn't logged in to Facebook.
}
});
I've found the source of the problem and a solution. I'm not sure this is the best solution so I'm open to other suggestions but if this can help other people, here is the thing:
The issue was that the Facebook library was not loaded yet, so the FB variable was undefined. For some reason if you try to do something with an undefined variable in Ember the app just won't work without even a warning. So the solution is to wait:
App.deferReadiness()
function checkFB() {
if (typeof FB !== 'undefined') {
APp.advanceReadiness()
}
else {
setTimeout(checkFB, 10);
}
}
setTimeout(checkFB, 10);
10 milliseconds is pretty short so the app is still initialized very quick, and in my tests the app starts after ~20 milliseconds. This still feels a bit hacky but in place of a better solution this will do for now.
As Aaron said you need to use fb.getLoginStatus to check if a user is already logged in. To make sure Facebook is loaded before you to make any calls you can use an initializer and defer the app until the SDK has loaded.
http://nerdyworm.com/blog/2013/04/03/ember-initializers/
Ember.Application.initializer({
name: 'init_fb',
initialize: function (container) {
window.App.deferReadiness();
Ember.$.getScript( '//connect.facebook.net/en_UK/all.js', function( ) {
FB.init( {
appId : 'xxxxxxxxxxxxx',
xfbml : true,
version : 'v2.0',
} );
window.App.advanceReadiness();
} );
}
});