getting "Uncaught TypeError: Cannot call method 'replace' of undefined" when doing FB.init using Facebooker2 - ruby-on-rails-3

I am using Facebooker2 to create a Facebook IFrame application, which is running as a tab inside a Facebook page.
My goal is to be able to use the social plugins, such as a like button and comments, etc. I tried to define them as follows
<div class="fb-like" data-href="http://www.myurl.com" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div>
and trying to initialize the FB JS SDK by calling
<%= fb_connect_async_js %>
which outputs
<div id="fb-root"><script async="" src="http://connect.facebook.net/en_US/all.js"></script></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'APP_ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true,
xfbml : true // parse XFBML
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
This has worked before, and stopped working after Facebook pushed their last platform update about a month ago. Now the Like button is not being rendered at all. I also tried the XFBML approach, no luck.
note: I am able to publish feeds using FB.publish, and I am also able to create a like button using the IFrame method.
I looked at the documentation and didn't see anywhere where it was mentioned that Social plugins cannot be used inside IFrame apps.
any ideas anyone?

I've encountered the same issue, and the only workaround i could find is to set a timer to execute FB.XFBML.parse();
If anyone has a better solution, I'd be thanksfull to hear it !
window.fbAsyncInit = function() {
setTimeout(function(){
FB.XFBML.parse();
FB.Event.subscribe('auth.login', function(response) {
fbLogin();
});
FB.Event.subscribe('auth.logout', function(response) {
fbLogout();
});
/* Additional initialization code here */
},
1000);
var params = {
appId : facebookAppId,
channelUrl : siteurl+'facebookChannelFile.php',
status : true,
cookie : true,
oauth : true,
xfbml : true
};
FB.init(params);
};

Related

How can I check if Google Identity Service migration was successful?

We have followed the Google Identity migration documentation and replaced the new code but used existing google OAuth client ID.
Previously, before migration we used to get a warning in console, please see the image attached-
Now, after we have added the new code the warning message is not showing in the console. Below is the new console image
But still we have received one reminder mail from Google with our app name and OAuth key that we still need to migrate.
So we are confused if the migration was successful or not? Please help? Do we have to create a new OAuth client ID and replace?
(Please note we are not seeing any warning in console related to this.)
Here is our code snippet-
<div class="bg-google text-white pt-3 pb-2 px-4 rounded-lg cursor-pointer ml-4 mr-4" #click="SocialLogin">
<img src="#/assets/images/pages/login/google.svg"/><span>Sign in with Google</span>
</div>
mounted() {
this.tokenClient= google.accounts.oauth2.initTokenClient({
client_id: process.env.VUE_APP_GOOGLE_OAUTH_KEY,
scope: "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile",
prompt: "consent",
callback: tokenResponse => this.handleCredentialResponse(tokenResponse) // your function to handle the response after login. 'access_token' will be returned as property on the response
});
},
methods: {
SocialLogin() {
this.tokenClient.requestAccessToken();
},
async handleCredentialResponse(response) {
this.$helper.showLoading();
const userInfo = await new Promise(resolve => {
const xhr = new XMLHttpRequest();
xhr.open('GET', `https://www.googleapis.com/oauth2/v3/userinfo`);
xhr.setRequestHeader('Authorization', `Bearer ${response.access_token}`)
xhr.onload = function () {
if (this.status >= 200 && this.status < 300)
resolve(JSON.parse(this.responseText));
else resolve({ err: '404' });
};
xhr.send();
});
if(userInfo){
localStorage.setItem("user_email", userInfo.email);
}
},
}
I checked with the team apparently there is a back log for these messages so they may have detected a few weeks ago that you were still using the old library and the message is just getting sent now.
You know you have upgraded and are no longer getting the error message so your all good.

how to get data from local google Auth?

I am facing a problem in findding a login data of user and user is logedin to my site using google auth platform and i want to get that login data and store data in my local storage and I am working on Angular 14
Kindly help if any one know the soluiton of this problem
Thanks
I had searched a lot but not find a convieniet solution
It's work for me in this way.
According to the new documentation of Google (https://developers.google.com/identity/gsi/web/guides/overview), you should follow next steps:
Create a google app in google cloud console platform and generate a client id.
Load the client library. Add this script "<script src="https://accounts.google.com/gsi/client" async defer>" between the <head></head> tags of your index.html file of Angular project.
Add this code on ngOnInit() function in the component that you would like to have "Sign in with Google button."
ngOnInit() {
// #ts-ignore
google.accounts.id.initialize({
client_id: "YOUR GOOGLE CLIENT ID",
callback: this.handleCredentialResponse.bind(this),
auto_select: false,
cancel_on_tap_outside: true,
});
// #ts-ignore
google.accounts.id.renderButton(
// #ts-ignore
document.getElementById("google-button"),
{ theme: "outline", size: "large", width: "100%" }
);
// #ts-ignore
google.accounts.id.prompt((notification: PromptMomentNotification) => {});
}
async handleCredentialResponse(response: any) {
// Here will be your response from Google.
console.log(response);
}
Add div or button element to the html file of this component, with the same id that you mentioned into the initialization. ( "google-button" ):
<div class="" id="google-button"></div>.
Let me know if you have any issues.

Aurelia - Trying to switch root and it cannot find the location

I have been following a variety of sources in particular Mathew James Davis with THIS blog entry and others.
I had in my boot.ts (main in other examples etc):
aurelia
.start()
.then(function () { return aurelia.setRoot(PLATFORM.moduleName("public/public/public")); });
});
which worked.
I am now running two roots and checking if a JWT exists in localstorage. It gets the jwt and stores it OK and I even obtain it correctly but it now doesnt recognise the root and I think I have a syntax error of some sort..
This is what I now have:
aurelia.start().then(() => {
var auth = aurelia.container.get(AuthService);
let root = auth.isAuthenticated() ? 'app/app/app' : 'public/public/public';
return aurelia.setRoot(PLATFORM.moduleName(root));
});
I am getting the following error:
Uncaught (in promise) Error: Unable to find module with ID: public/public/public
I do not know why it now doesnt work when the exact same path worked when entered directly..
UPDATE
Ok so I thought I would refactor this and utilise the section of code that works:
This is what I changed it to:
var auth = aurelia.container.get(AuthService);
let authenticated = auth.isAuthenticated();
console.log("authenticated: ", authenticated);
if (authenticated) {
aurelia
.start()
.then(function () { return aurelia.setRoot(PLATFORM.moduleName("app/app/app")); });
} else {
aurelia
.start()
.then(function () { return aurelia.setRoot(PLATFORM.moduleName("public/public/public")); });
}
Now it shows a blank loading page with "loading" and shows this at in the console:
authenticated: false
aurelia-logging-console.js:27 INFO [aurelia] Aurelia Started
client.js:82 [HMR] connected
Note - if just have the original code with app/app/app in it and authentication= true then it also shows correctly.
So both roots work but not with a check..
Finally fixed this. I eventually changed my original code:
aurelia.start().then(function () {
var auth = aurelia.container.get(AuthService);
var root = auth.isAuthenticated() ? "app/app/app" : "public/public/public";
aurelia.setRoot(root);
to:
aurelia.start().then(() => {
var auth = aurelia.container.get(AuthService);
let root: string = auth.isAuthenticated() ? PLATFORM.moduleName('app/app/app') : PLATFORM.moduleName('public/public/public');
aurelia.setRoot(root, document.body)
});
and it now works. In the end it was my lack of programming skills however if anybody else has a problem they might try this for switching routes.

$firebaseSimpleLogin() for facebook doesn't work when preferRedirect is true

Scenario:
Ensure not currently logged into Facebook
Navigate to webapp on localhost
Click "login" and it properly takes you to the Facebook login screen without using a pop-up
Login using valid credentials
Automatically redirect back to localhost
Doesn't appear to be logged in and auth.user is null
Click login again and the request is cancelled automatically by firebase
Navigate to facebook (and may need to refresh) and you are logged in, so the login did "work"
If you use preferRedirect:false the entire scenario works as expected
Versions:
angular and angular-route: 1.3.0-b14
firebase, firebase-simple-login, and angularfire: 1.0.17
Code snippets
/* html snippet */
<div id="login">
<span ng-show="auth.user">
{{auth.user.id}} | Logout
</span>
Login
</div>
/* javascript snippet */
angular.module('<removed_for_this_post>', ['ngRoute', 'firebase'])
.value('firebaseURL', 'https://<removed_for_this_post>.firebaseio.com/')
.factory('FirebaseData', function(firebaseURL) {
return (new Firebase(firebaseURL));
})
.config(function($routeProvider) {
$routeProvider
.when('/', {
controller:'HomeCtrl',
templateUrl:'home.html'
})
.otherwise({
redirectTo:'/'
});
})
.controller('HomeCtrl', function($scope, $firebase, FirebaseData, $firebaseSimpleLogin) {
var ref = new Firebase("https://<removed_for_this_post>.firebaseio.com/");
$scope.auth = $firebaseSimpleLogin(ref);
/* Login using facebook */
$scope.facebookLogin = function() {
$scope.auth.login('facebook', {
rememberMe: true,
preferRedirect: true
});
};
/* Logout using facebook */
$scope.facebookLogout = function() {
$scope.auth.$logout();
};
});
Any thoughts on what I am doing wrong here?
Thanks!

Facebook JS sdk Oauth onload

I trye to use Facebook JS SDK and I fell on a problem.
I want that after the page load, the user click on the FB button, and then,
if he is already logged I change location,
if not,
it trigger the fb loggin popup
here is my code "
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '<?php echo $action->appId; ?>', // App ID from the app dashboard
status : true, // Check Facebook Login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // Look for social plugins on the page
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
$(location).attr('href','nexPage.php');
} else if (response.status === 'not_authorized') {
FB.login();
} else {
FB.login();
}
});
My problem come with the fact that the facebook authResponseChange trigger onload so if the user is already logged and just arrive on the page he is directly send to the next page, and I don't want that !
I want the user to see the page first, click, then login/or not and go to the next page
Does somebody have an idea how to do that ?
(and no click event possible cause after the user logged, FB reload the page)
found !
put the status to false
FB.init({
appId : '<?php echo $action->appId; ?>', // App ID from the app dashboard
status : false, // Check Facebook Login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // Look for social plugins on the page
});
Sorry for disturb