Trouble setting up facebook login - javascript

I am building a hybrid mobile app based out of JavaScript, CSS and HTML. I am using the Intel XDK to develop and deploy the app.
For Facebook integration I am using the following third party plugin to work it out.
My aim is to get it to work both on iOS and Android. I have done the followings:
<button onclick="fblogin()"> Login </button>
Script:
<script>
function fblogin() {
var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
}
facebookConnectPlugin.login(Array strings of permissions, Function success, Function failure);
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
}
</script>
The issues:
I have already enabled the plugin with my javascript api on the intel xdk.
fblogin() not defined at the following line:
facebookConnectPlugin.login(Array strings of permissions, Function success, Function failure);
I have read through the guide but is still confused. I would appreciate if someone could give me a step by step guide on making this work.

I would suggest to look at the sample code on the README (https://github.com/Wizcorp/phonegap-facebook-plugin#sample-code)
You can write your function like this:
function fblogin() {
var fbLoginSuccess = function (userData) {
alert("UserInfo: " + JSON.stringify(userData));
}
facebookConnectPlugin.login(["public_profile"],
fbLoginSuccess,
function (error) { alert("" + error) }
);
}
i.e remove the
facebookConnectPlugin.login(Array strings of permissions, Function success, Function failure)
line.

Related

JavaScript - Trigger Twitter intent "follow" callback only if user actually follows

Product I am working on: Requestly - Chrome and Firefox Extension Setup redirects, modify headers, switch hosts, insert user scripts (https://www.requestly.in/)
What I am trying to do: Requestly offers free 30 days access to GOLD Plan if user completes a set of few steps. One of such steps is to follow us on Twitter. I want to verify if the user has actually followed us on Twitter.
//After loading widgets.js
function followIntent (intentEvent) {
console.log("User Followed")
};
twttr.ready(function (twttr) {
twttr.events.bind('follow', followIntent);
});
Problem: The "followIntent" function is getting triggered as soon as user clicks the Follow button. I want it to be called only after user has successfully followed us. How can I achieve this?
Assuming you're running into a problem that the follow event occurs in between the events of user clicking the "following" button and the actual "following" happens. You can always call the Twitter API to verify it via GET followers/ids. Though it seems a bit unnecessary...
function followIntent (intentEvent) {
if (!intentEvent) return;
followerVerification(intentEvent.data.user_id);
};
async function followerVerification (userID) {
// make your API request here
var userList = await twitterAPIRequest();
if (userList.includes(userID)){
console.log("User Followed")
} else {
console.log("User Not Followed")
}
}
function twitterAPIRequest() {
var settings = {
"async": true,
"url": "https://api.twitter.com/1.1/followers/ids.json?screen_name=twitterdev",
"method": "GET",
"headers": {
// Your app autherization stuff
}
}
$.ajax(settings).done(function (response) {
return response.ids;
});
}
twttr.ready(function (twttr) {
twttr.events.bind('follow', followIntent);
});

Cordova Camera access crash app on Nexus 7 with Android 6.0.1

Using Cordova 6.3.1, I installed the following Crodova plugins:
cordova-plugin-camera, cordova.plugins.diagnostic, phonegap-plugin-barcodescanner
I'm using the following JavaScript code to access the Camera and scan a QR code:
function scanQR() {
cordova.plugins.diagnostic.requestCameraAuthorization(function(status) {
console.log("Authorization request for camera returned " + status);
if (status == cordova.plugins.diagnostic.permissionStatus.GRANTED) {
try {
cordova.plugins.barcodeScanner.scan(scanQRDone, function (error) {
console.log(error);
});
} catch (e) {
console.log(e.message);
}
}
}, function (error) {
console.log(error);
});
}
function scanQRDone(result) {
console.log(result);
}
The requestCameraAuthorization call prompts for a confirmation on the device and when allowed returns status GRANTED.
However the call to cordova.plugins.barcodeScanner.scan simply crashes the application on the Nexus 7.
The actual line in which the crash occurs is cordova.js line 940:
var msgs = nativeApiProvider.get().exec(bridgeSecret, service, action, callbackId, argsJson);
Where service="BarcodeScanner" and action="scan"
Seems like some kind of version mismatch in native code, any ideas are welcomed.
Creating a new ionic application from scratch and copying the content of the www folder into it has resolved the problem.
in the file config.xml add this
< platform name="android" > <br>
< preference name="android-targetSdkVersion" value="23" /> <br>
< /platform>

Cannot record audio with Cordova Media plugin on Windows (Phone) 8.1

I'm trying to create an app that allows the user to record audio. I'm using the cordova-plugin-media for this.
Using the sample from the documentation I can record sound on iOS (specifying a *.wav file), Android (*.amr), Windows Phone 8 (*.aac), but Windows Phone 8.1 doesn't work. I've tried it with *.mp3, *.wma, and *.m4a, but in every case I get this error:
No suitable transform was found to encode or decode the content.
Here's part of the code:
var that = this;
try {
this._media = new Media('recording.mp3', function () {
that._log('Audio success');
}, function (e) {
that._log('Error: ' + e.code + ': ' + e.message);
});
// Bind buttons
document.querySelector('#recordStart').addEventListener('click', function () {
// Record
that._log('Recording...');
that._media.startRecord();
});
document.querySelector('#recordStop').addEventListener('click', function () {
that._log('Recording stopped');
that._media.stopRecord();
});
}
catch (e) {
this._log('An error occurred!');
this._log(e.message);
}

Not able to get error in pubnub javascript callback

I am following the howto in this blog post: http://www.pubnub.com/blog/sending-android-push-notifications-via-gcm-javascript-using-phonegap/
Up til now I have done the following:
Created a new project in Google Dev Console
Turned on Google Cloud Messaging for Android
Got the sender ID (project number) and a server
key
Then added push plugin to existing project:
$ cordova plugin add https://github.com/phonegap-build/PushPlugin.git
Then copied PushNotification.js from the plugin to my js lib folder.
I am loading both this js file and the pubnub cdn with requirejs, which seems to work fine.
I created a module with the scripts from 2.2 in the howto.
define(['env-config','datastore/localstore','jquery','push','pubnub'],function (EnvConfig,Store) {
var pushNotification = window.plugins.pushNotification;
function register() {
pushNotification.register(
successHandler,
errorHandler,
{ 'senderID':EnvConfig.push.senderid, 'ecb':'onNotificationGCM'}
);
}
function successHandler(result) {
console.log('Success: '+ result);
}
function errorHandler(error) {
//** The following line throws:
//** java.lang.Long cannot be cast to java.lang.String
console.log('Error:' + error);
}
function onNotificationGCM(e) {
switch(e.event){
case 'registered':
console.log("Device registered with id "+e.regid);
Store.set("pushid"+e.regid);
/*if (e.regid.length > 0) {
deviceRegistered(e.regid);
} */
break;
case 'message':
if (e.foreground){
//What needs to be done when app is in the foreground
//while receiving a notification
console.log('A notification has been received');
}
break;
case 'error':
console.log('Error: ' + e.msg);
break;
default: console.log('An unknown event was received');
break;
}
}
var module = {
init: function() {
register();
}
};
return module;
});
When device is ready, I call the init function of this module.
At the moment register() fails and executes the errorHandler callback. But console.log fails with: java.lang.Long cannot be cast to java.lang.String. Therefore I have no idea what to do next...
Any pointers is much appreciated.
Samsung Galaxy S5
Android 4.4.2
Chrome 30.0 (in webview)
Cordova 3.6.3-0.2.13
Ah, I think I know what's going on-
Your sender ID has to be in string! You are probably using it as a number.
BTW, thanks for trying out the tutorial I wrote :-)

Sendsms plugin not working on Phonegap

I'm trying to send a message using The "Sendsms"plugin for phone gap on Android.
But when I call the function, I get this error:
Uncaught TypeError: Cannot call method 'send' of undefined at file
This is the JS code I'm using :
function onDeviceReady () {
$('#send').bind('click', function () {
alert('Phone: ' + $('#friendName').val() + ' Message: ' + $('#MessageContent').val());
window.plugins.sms.send($('#friendName').val(),
$('#MessageContent').val(),
function () {
alert('Message sent successfully');
},
function (e) {
alert('Message Failed:' + e);
}
);
});
}
document.addEventListener("deviceready", onDeviceReady, false);
I got the java code from here & added the permission:
<uses-permission android:name="android.permission.SEND_SMS"/>
And added the plugin to Plugins.xml.
Do you know what's the problem ?
Depending on what version of PhoneGap you are using you may just have to go into the smsplugin.js and replace the instances of "PhoneGap" with "cordova".

Categories

Resources