CORONA SDK - facebook.showDialog() appears and disappears after a while - facebook

I've added Facebook to my application.
The login is ok, except that facebook.login() opens the browser instead of the native Facebook App, but then, when I call Facebook.showDialog() the popup pops up, but after a second or two it disappears.
Note that I get this behavior on iOS only, while on Android it is working fine.
I'm using the code below in my game.lua file:
local function facebookListener( event )
if ( "session" == event.type ) then
if ( "login" == event.phase ) then
local access_token = event.token
facebook.showDialog( "feed", { name = "SuperCool Game Coming soon", description = "Trying to figure out how to get my game to rule the world.", picture = "http://omnigeekmedia.com/wp-content/uploads/2011/05/omniblaster_promo-300x300.png", link = "http://www.omnigeekmedia.com/"})
end
elseif ( "request" == event.type ) then
print("facebook request")
if ( not event.isError ) then
local response = json.decode( event.response )
end
elseif ( "dialog" == event.type ) then
print( "dialog", event.response )
end
end
fbAppID = "my app ID" --replace with your Facebook App ID
function logOnFacebook(event)
if(event.phase=="ended")then
facebook.login( fbAppID, facebookListener, { "user_friends", "publish_actions" } )
end
end
["facebook"] =
{
publisherId = "com.coronalabs",
supportedPlatforms = { iphone = true, ["iphone-sim"] = true },
},
I'm running on build 2015.2729.
How can I manage to get Facebook work?

I would suggest updating to the v4 version of the plugin. While it's technically still in beta, it's required for iOS 9 builds. See:
https://coronalabs.com/blog/2015/07/24/facebook-v4-plugin-android-beta/
https://coronalabs.com/blog/2015/09/01/facebook-v4-plugin-ios-beta-improvements-and-new-features/

Browsing through the source code of the old Facebook plugin, this error will occur in the event that a permission requested wasn't granted!
In the source code for the old Facebook plugin, this can be seen in the FBSessionReauthorizeResultHandlers.
for ( int i = 0; i < [publishPermissions count]; i++)
{
if ( ![publishSession.permissions containsObject:[publishPermissions objectAtIndex:i]] )
{
release = true;
publishError = [[NSError alloc] initWithDomain:#"com.facebook" code:123 userInfo:nil];
break;
}
}
This will also occur for read permissions that were requested and not granted.
The issue has since been fixed in the Facebook-v4 plugin.

Related

Disable Launch URL in OneSignal Push Notification when opened

Unable to disable the launch url in OneSignal push notification when opened. Tried toggling kOSSettingsKeyInAppLaunchURL from true to false and it still opens up Safari.
What can I do to completely remove the launch Url? Thanks in advance.
My code in for OneSignal app.component.ts is as follows,
if (this.appConfig.Onesignal_Enable == true) {
this.oneSignal.startInit(this.appConfig.OneSignal_AppID, this.appConfig.GCM_SenderID);
this.oneSignal.iOSSettings({
kOSSettingsKeyInAppLaunchURL: false,
kOSSettingsKeyAutoPrompt: true,
});
this.oneSignal.handleNotificationOpened().subscribe(() => {
// do something when a notification is opened
this.navCtrl.navigateForward('positions');
});
this.oneSignal.endInit();
}
Solved it on the web side instead with PHP. For anyone running on WordPress, this is a great filter.
add_filter( 'onesignal_send_notification', 'onesignal_send_notification_filter', 10, 4 );
function onesignal_send_notification_filter($fields, $new_status, $old_status, $post) {
// Set player ids as subscribed to onesignal notification (see users in onesignal dashboard)
$fields['isAndroid'] = true;
$fields['isIos'] = true;
$fields['isAnyWeb'] = false;
$fields['isChrome'] = false;
$fields['data'] = array(
"myappurl" => $fields['url']
);
/* Unset the URL to prevent opening the browser when the notification is clicked */
unset($fields['url']);
return $fields;
}

facebook.login() is not working in Corona SDK

I have went threw all the steps, creating a key hash for android for my game build in corona. I have create a Button for user login Facebook account. But don't have any error message and response when user touch the Button. Only have print output.
What am I missing? Please help.
I have create the Key Hashes using OPENSSL
Enter App ID from Facebook Developers
Enter Key Hashes to Facebook Developers
Enable "Single Sign On" and "Deep Linking"
Enter Class Name "com.ansca.corona.CoronaActivity" on Facebook Developers
include "android.permission.INTERNET" in build.settings
local facebook = require ("facebook")
local fbAppID = "49911xxxxxx"
local function onClick( event )
if ( "ended" == event.phase ) then
print( "Button was pressed and released" )
facebook.login( fbAppID, facebookListener, { "publish_actions, email" } )
end
end
-- Facebook Button
FacebookButton = widget.newButton
{
defaultFile = "images/fb.png" ,
width = 240,
height = 120,
onEvent = onClick,
}
FacebookButton.x = display.contentWidth / 2
FacebookButton.y = display.contentHeight / 2
I am unsure if you have fixed this problem but I too have been having problems with this. When you go to log in through Facebook and it gives you an error saying:
"invalid key hash code, it does not match xxxxxxxxxxxxx configure it in (your website here)" I copied the hash code and checked it over and over again...
Only to FINALLY realize that the lowercase "L" was actually an uppercase "i" o.0 it fixed it! Good luck to ya!
Also, here is a little code snippit that helped me a little
local function facebookListener(event)
if (event.type == "session") then
if (event.phase == "login") then
sessionToken = event.token
local response = event.response
native.showAlert("My Response", response)
--facebook.request("me", "GET", {fields = "email"})
elseif (event.type == "request") then
local response = event.response
native.showAlert("My Response", response)
end
end
end
facebook.login( appId, facebookListener, {"publish_actions, email, public_profile"})

Trying to retrieve facebook user email using facebook connect for cordova 3.2

I'm developing an android app wherein it requires to be logged into the app via facebook. I'm using facebook connect for cordova 3.2 and its working fine.But the problem is I'm not able to get the user's email address. I tried scope : email , permissions : 'email', but it simply does not work.I have installed facebook sdk for android the cordova 3.2 version and configured that with my project. I call the facebook login uri with a button click event.
var facebookConnect;
$("#facebookfbtn").unbind("click").click(function () {
facebookConnect.login(loginCallback, true);
});
document.addEventListener("deviceready", deviceready, false);
function deviceready(){
facebookConnect = window.plugins.facebookConnect;
}
loginCallback = function(result){
alert(result);
if(result == "OPENED")
{
facebookConnect.me(meCallback);
}
}
logoutCallback = function(result){
alert(result);
}
meCallback = function(result){
alert(JSON.stringify(result));
//var test = JSON.stringify(result);
alert('Good to see you, ' + result.name + '!' + '\n'+ 'Your Details :'+ '\n'+'Location:'+result.location+'\n'+'Email: '+result.email);
}
statusCallback = function(result){
alert(result);
}

phonegap - using external site as app - facebook login

I'm building a app site running through phone gap. Phone gap simply checks the user has internet connection and loads an external web app into the frame. I can navigat through the site fine with no blibs but as soon as I try the login to Facebook (either PHP redirect or javascript SDK) the app suddenly gets its navbar back or opens a new window (javascript SDK).
Is there anyway I can prevent this?
regards
It took some doing but using the ChildBrowser plugin, I've managed to login! (this is for android) I've used some code from a facebook connect plugin which didnt work for me, re wrote some stuffs so I could understand it and now works. Chears Juicy Scripter!
var fb_success = 'https://www.facebook.com/connect/login_success.html';
var fb_logout = 'https://www.facebook.com/connect/login_failed.html';
var fb_logout_ = 'http://m.facebook.com/logout.php?confirm=1&next=' + fb_logout;
var authorize_url = '';
var my_client_id = '##################';
var my_secret = '######################';
var my_type = 'user_agent';
var my_display = 'touch';
var token = false;
var fb_code = false;
var device_ready = false;
var ajax_url = '';
function logged_in(){
// alert('do what you need to do!');
}
function fb_force_logout(){
}
function fb_auth_check(){
console.log('fb_auth_check()');
if( fb_code !== false ) {
console.log('ajax test instigated...');
ajax_url = 'https://graph.facebook.com/oauth/access_token?client_id=' + encodeURIComponent(my_client_id) + '&client_secret=' + encodeURIComponent(my_secret) + '&code=' + encodeURIComponent(fb_code) + '&redirect_uri=' + fb_success;
$.ajax({
url: ajax_url,
type: 'POST',
success: function(html){
token = html.split("=")[1];
console.log('success! token = ' + token);
window.plugins.childBrowser.close();
fb_init();
},
error: function(error) {
console.log('there was an error...' + ajax_url);
window.plugins.childBrowser.close();
}
});
}
}
function fb_track_redirects(loc){
console.log('redirect tracked... ' + loc);
if ( loc.indexOf(fb_success) >= 0 || loc.indexOf(fb_success) > -1 ) {
fb_code = loc.match(/code=(.*)$/)[1]
console.log('success redirect... fb_code=' + fb_code);
fb_auth_check();
window.plugins.childBrowser.close();
} else if ( loc.indexOf(fb_logout) >= 0 || loc.indexOf(fb_logout) > -1 ) {
window.plugins.childBrowser.close();
}
}
function inner_init(){
console.log('inner_init()');
if( token === false ) {
console.log('token was false...');
authorize_url += "https://graph.facebook.com/oauth/authorize?";
authorize_url += "client_id=" + encodeURIComponent(my_client_id);
authorize_url += "&redirect_uri=" + encodeURIComponent(fb_success);
authorize_url += "&display=" + encodeURIComponent(my_display);
authorize_url += "&scope=publish_stream,offline_access";
console.log('instigated location change...');
window.plugins.childBrowser.onLocationChange = function(loc){
fb_track_redirects(loc);
}
console.log('open Facebbok login window');
window.plugins.childBrowser.showWebPage(authorize_url);
}else{
logged_in();
}
}
function fb_init(){
console.log('fb_init()');
if( device_ready === false ) {
console.log('first device run...');
document.addEventListener("deviceready", function(){
device_ready = true;
console.log('device ready...');
inner_init();
}, false);
}else{
inner_init();
}
}
$(document).ready(function(){
$('#login').bind('click', function(){
fb_init();
return false;
})
});
</script>
This is how it works for all apps native or web without patching the SDK code.
This is probably can be done, but will require digging into code. The question is do you really need it? This is a desired behavior.
You can try to use PhoneGap Facebook plugin and enable Single Sign On so native Facebook App if exists will be opened instead of browser to authenticate the user.
BTW,
Apps that are just external sites wrapped mostly rejected in app store.
Update:
Where is some points that may be also helpful in answer (by Facebook employee) to similar question How can I use an access token to circumvent FB.login().
Also have a look on ChildBrowser PhoneGap plugin (and Example).

strophe to register user on ejabberdctl

I would like to add a user on ejabberd server using strophe with out typing ejabberdctl register uname servename passwd at command prompt. Is it possible to implement?. Is there any
XMPP protocol exists to register an user?
Thanks
Sathi
Yes it is possible... you need to allow for inline registration on the server. Once that's done, you can certainly do it from any client or client library, include strophe.js.
Use mod_admin_extra and mod_rest then you get a full restfull access to jabberctl + some extra commands. Search the module documentation for more information on how to set this up.
I am using strophe.register.js
$("#register").click(function () {
var connect = new Strophe.Connection('http://yourserver.com/http-bind');
var callback = function (status) {
if ( status === Strophe.Status.REGISTERING ) {
console.log('REGISTERING')
}
else if ( status === Strophe.Status.REGIFAIL ) {
console.log('REGIFAIL')
}
else if ( status === Strophe.Status.REGISTER ) {
console.log('REGISTER')
connect.register.fields.username = "joe"
connect.register.fields.password = "doe"
connect.register.submit();
}
else if ( status === Strophe.Status.SUBMITTING ) {
console.log('SUBMITTING')
}
else if ( status === Strophe.Status.SBMTFAIL ) {
console.log('SBMTFAIL')
console.log('Something went wrong...');
}
else if ( status === Strophe.Status.REGISTERED ) {
console.log('REGISTERED')
console.log('Your account has been created successfully and is ready to use!');
}
}
connect.register.connect("yourserver.com", callback);
});