React-native Log in with Facebook App refreshes app - facebook

I am using react-native-fbsdk and am on IOS. When users log in with Facebook their are two buttons they can press. Log in with the Facebook App or Log in with Phone Number or Email Address. Logging in with the Phone Number or email address works perfectly, I get the user object and create a user account for them. But when users press Log in with the Facebook App I don't get sent a user object, and the whole app refreshes where they get pushed to the log in page and the Facebook button has turned to Log out. I am not too sure on how to approach this as when users log in with the Facebook App none of my console.logs or alerts are getting called and the whole app just refreshes. Any help would be very much appreciated.
<LoginButton
readPermissions={["email","public_profile"]}
onLoginFinished={
(error, result) => {
console.log("onLoginFinished: ", result);
if (error) {
console.log("login has error: ", result.error);
} else if (result.isCancelled) {
console.log("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
let accessToken = data.accessToken
console.log("accessToken.toString(): ", accessToken.toString())
const responseInfoCallback = (error, result) => {
if (error) {
console.log('Error fetching data: ', error)
//lert('Error fetching data: ' + error.toString());
} else {
console.log("responseInfoCallback:", result)
this.state.fbobj = result;
this.sendAjax();
//alert('Success fetching data: ' + result.toString());
}
}
const infoRequest = new GraphRequest(
'/me',
{
accessToken: accessToken,
parameters: {
fields: {
string: 'email,name'
}
}
},
responseInfoCallback
);
// Start the graph request.
new GraphRequestManager().addRequest(infoRequest).start()
}
)
}
}
}
onLogoutFinished={() => console.log("Logout")}

In your button action, you will need something like this:
import { LoginManager, AccessToken } from 'react-native-fbsdk'
handlePressFacebookLogin = () => {
LoginManager.logInWithReadPermissions(['public_profile', 'email']).then(
(result) => {
if (!result.isCancelled) {
AccessToken.getCurrentAccessToken().then((data) => {
console.log(data)
})
}
}
)
}

Related

Mercado Pago Client onPaymentMethodsRecieved

I am trying to integrate Mercado Pago to my React aplication, first I want to connect the client so I can set up some alerts (/process-payments is going to be done through python)
I am having a problem. I can not log PaymentMethods nor Issuers. Strangely my issuers field is populated. For example whenever I put a random card Number I get logged the installments yet not the issuers (although I can see them)
Console and Product image
The following is my code:
useEffect(() => {
if (MercadoPago) {
const mp = new MercadoPago(
PUBLIC_KEY
);
console.log("mp es", mp);
const cardForm = mp.cardForm({
amount: "200",
autoMount: true,
form: formConfig,
callbacks: {
onFormMounted: (error) => {
if (error) {
return console.warn("Form mounted handling error: ", error);
}
console.log("Form Mounted");
},
onPaymentMethodsRecieved: (error, paymentMethods) => {
console.log("In Payment methods");
if (error) {
window.alert("No payment methods");
}
console.log("Payment Methods Available", paymentMethods);
},
onIssuersRecieved: (error, issuers) => {
if (error) return console.warn("issuers handling error: ", error);
console.log("Issuers available: ", issuers);
},
onInstallmentsReceived: (error, installments) => {
if (error)
return console.warn("installments handling error: ", error);
console.log("Installments available: ", installments);
},
onCardTokenRecieved: (error, token) => {
if (error) {
return console.warn("Token no se pudo crear: ", error);
}
console.log("Token available: ", token);
},.......}
I think you misspelled 'onPaymentMethodsRecieved', it should be onPaymentMethodsReceived. The same happens in the others logs.

Login with facebook in React Native

I am working on a project that requires a facebook login, I have tried lots of things but non of them seem to work.
This is the code I have:
import FBSDK from 'react-native-fbsdk';
const {
LoginButton,
} = FBSDK;
/** Code */
render() {
return (
<LoginButton
publishPermissions={['publish_action']}
onLoginFinished={
(error, result) => {
(error) {
alert('Login failed with error: ' + result.error);
} else if (result.isCancelled) {
alert('Login was cancelled');
} else {
alert('Login was successful with permissions: '
+ result.grantedPermissions)
}
}
}
onLogoutFinished={() => alert('User logged out')}
/>
}
}
If you know how to solve this please let me know.
Thank you.

Integrating Branch.io in Ionic App

I am trying to send my app's link form my website with a token in the link like this :
branch.link({
stage: 'new user',
data: {
token: 543322
}},
function(err, link) {
console.log(err, link);
});
then when the app is installed by user after clicking on the link, i want to get this token to register the user.
I tried by reading Branch.io docs and implementing it but it's not working.
Can somebody tell me an Example to how to make it work?
Code in my app controller is like this
(():void => {
'use strict';
angular
.module('xyz')
.controller('abc', abc);
function abc (
$window
) {
let vm = this;
$window.Branch.setDebug(true);
$window.Branch.initSession().then(function (res) {
console.log(res);
alert('Response: ' + JSON.stringify(res));
}).catch(function (err) {
console.error(err);
alert('Error: ' + JSON.stringify(err));
});
$window.Branch.getFirstReferringParams().then(function (res) {
// Success Callback
alert('res'+res);
}).catch(function (err) {
// Error Callback
alert('err'+err);
});
$window.Branch.getLatestReferringParams().then(function (res) {
// Success Callback
alert(res);
}).catch(function (err) {
// Error Callback
alert(err);
});
function DeepLinkHandler (data) {
alert('Data from initSession: ' + data.data);
}
$window.DeepLinkHandler = DeepLinkHandler;
})();
Alex from Branch here: there are three steps to this process:
1. Create the link
You're doing this already with the code you provided in your question.
2. Integrate the Branch SDK into your app
The docs page covering the steps for this is here: https://dev.branch.io/getting-started/sdk-integration-guide/guide/cordova/
3. Watch for the incoming link, and route it
The docs page covering what you need for this is here: https://dev.branch.io/getting-started/deep-link-routing/advanced/cordova/
Basically, it is a function that will look something like this:
function DeepLinkHandler(data) {
console.log("received data: " + JSON.stringify(data));
for (key in data) {
if ((key != "type" && key != "source" && key != "bubbles" && key != "cancelBubble") && data[key] != null) {
console.log(key + ": " + data["key"]);
}
}
if (data["token"]) {
// load the view to register the user based on your token
} else {
// load your normal view
}
}

Phone-gap Login with Facebook get same user id for different user

I tried login with facebook in my phonegap application after login successfully get response but in that response i get same user id for different different user.
I tried following code for login with facebook :-
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,function (error) { alert("" + error) }
);
var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
}
I get Following response every time for different different Facebook Users.
login object {"id":"784749268250297","first_name":"XXX","timezone":5.5,"email":"XXX#gmail.com","verified":true,"name":"XXX Jivani","locale":"en_US","link":"https://www.facebook.com/app_scoped_user_id/784749268250297/","last_name":"XXX","gender":"male","updated_time":"2014-09-10T16:28:22+0000"}
I solve this problem after some research.
first need to check loginstatus for user when status connected then need to logout first and then re login using different user then get different user id.
here my code :-
facebookConnectPlugin.getLoginStatus(
function (status) {
alert("current status: " + JSON.stringify(status));
if (status.status == "connected") {
facebookConnectPlugin.logout(function(){
alert("LOGOUT SUCCESS");
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
},function(){
alert("LOGOUT FAIL");
});
}
else{
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
}
},
function (e) {
alert("Failed: " + e);
});
var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
console.log("UserInfo: "+JSON.stringify(userData));
}
Thanks.

Facebook phonegap login

I am trying to log in with Facebook using PhoneGap. It seems to works well.
But on iOS 6.0, the login failed with the message "The operation couldn't be completed.(com.facebook.sdk error 5)".
If I don't set the account in setting of my iPhone, the plugin logged in using browser.
There is no problem.
But if I set the account in the setting, it shows upon message.
If I close the app, and launch again, it logs in successfully.
This function checks whether logged in already.
function getLoginStatus() {
FB.getLoginStatus(function(session) {
console.log('Got the user\'s session(facebook): ', session);
if (session.status == 'connected') {
FB.api('/me', {
fields: 'id, name, email'
},
function(response) {
if (response.error) {
console.log('get user name failed');
login(); // login to Facebook.
}
else
{
console.log('FB name, ' + response.name);
console.log('FB id, ' + response.id);
console.log('FB email, ' + response.email);
siteLogin(response); // login to my site.
}
});
} else {
console.log('get user name failed 2');
login(); // login to Facebook
}
});
}
Facebook login function
function login() {
FB.login(
function(response) {
if (response.session) {
alert('logged in');
} else {
alert('not logged in');
}
},
{ scope: "email" }
);
}
This is the event function.
FB.Event.subscribe('auth.login', function(response) {
FB.api('/me',{ fields: 'id, name, email' }, function(response1) {
if (response1.name !== undefined)
{
siteLogin(response1); // login to my site.
}
else
{
// I think here I get the message "The operation couldn't be completed.(com.facebook.sdk error 5)"
alert('error.');
}
});
});