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
}
}
Related
I am integrating Skype Web SDK audio service in my IONIC application. Everything works fine but I am not able to make a call. When I click on button to make a call following code gets call and I am getting Beep sound and then error about Pluginnotinstalled.
var conversation = application.conversationsManager.getConversation('tel:+XXXX');
conversation.selfParticipant.audio.state.when('Connected', function () {
console.log('Connected to audio call');
});
conversation.state.changed(function (newValue, reason, oldValue) {
console.log('Conversation state changed from', oldValue, 'to', newValue);
});
conversation.participants.added(function (participant) {
console.log('Participant:', participant.displayName(), 'has been added to the conversation');
});
conversation.audioService.start().then(function() {
console.log('The call has been started successfully');
}, function (error) {
console.log('An error occured starting the call', error);
});
When I run this code, I am getting error, Plugin not Installed. There's no description about what plugin they want.
An error occured starting the call
Error: PluginNotInstalled
Exception — skype-web-sdk.js:20782
(anonymous function) — skype-web-sdk.js:35814
exec2 — skype-web-sdk.js:21498
exec — skype-web-sdk.js:21478
dequeue — skype-web-sdk.js:21253
process — skype-web-sdk.js:21274
When I checked in details, The error is coming from below code of skype-web-sdk.js
function init(specs) {
tm && tm.record(Web.TelemetryEvent.PluginManager, {
action: 'init',
state: state()
});
if (state() == Media.PluginManager.State.Uninitialized) {
var id = '__mainPluginManager_' + guid().replace(/-/g, '_');
Media.log('PluginManager::init - id = ' + id);
language = (specs && specs.language) || "en-us";
isRtl = (specs && specs.rtl) || false;
var PluginObjectCtor_1 = (specs && specs.PluginObject) || Media.PluginObject;
tm = specs && specs.tm;
assert(!task || task.state() != 'pending');
task = new Task('Loading the media plugin.', {
cancel: function (reason) {
Media.log('PluginManager::init canceled ' + id);
stopLoadTimer();
reset(reason);
task.reject(reason);
}
});
tm && tm.monitor(task.promise, Web.TelemetryEvent.PluginManager, {
action: 'initPluginMgr',
state: state(),
id: id
});
state.set(Media.PluginManager.State.Initializing);
isPluginInstalled.get().then(function (installed) {
if (!installed)
throw Exception('PluginNotInstalled');
pluginObj = PluginObjectCtor_1({
id: id,
managerId: '_'
});
pluginObj.event(onPluginObjectEvent, 'async');
pluginObj.state.changed(onPluginObjectState);
Media.watch('pluginObject(' + id + ')::state', state);
Media.log('PluginManager::init - creating inner object');
try {
pluginObj.createInnerObject({
hide: true,
hookEvents: true
});
}
catch (err) {
state.set(Media.PluginManager.State.Uninitialized);
if (task.state() == 'pending')
task.reject(err);
}
}).catch(function (err) {
state.set(Media.PluginManager.State.Uninitialized);
if (task.state() == 'pending')
task.reject(err);
});
}
else {
// init has already been called and the plugin is either
// initializing or is already initialized; in either case
// we will return an existing promise
assert(task);
}
return task.promise;
}
Which browser are you using?
IE11 and Safari both need the Skype for Business Web App plugin which can ben found here: Getting started with Skype Web SDK development
Here you can find more information on how to check if the plugin is installed.
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)
})
}
}
)
}
I'm working with the facebook API and I need to get the profile data to save it in a database. The code returns fine, but when I try to access the data it shows me error because they are null.
This is my code:
this.fb.login(['public_profile', 'user_friends', 'email'])
.then((res: FacebookLoginResponse) => {
token = res.authResponse.accessToken;
userId = res.authResponse.userID;
if (res.status == 'connected') {
this.fb.api('/' + res.authResponse.userID + '?fields=id,first_name,last_name,gender, email,birthday', [],
function onSuccess(result) {
var name = JSON.stringify(result.first_name);
this.register(name);
},
function onError(error) {
console.log(error);
});
} else {
console.log('Not logged in');
}
}).catch(e => console.log('Error logging into Facebook', e));
When I try to call the register method it generates error because the method does not exist, but this is not true. I also tried to save the result of name to a global variable but when it is to be assigned it shows that it can not assign the variable, ie as if the global variable was not defined.
The solution was to change
function onSuccess(result) {
var name = JSON.stringify(result.first_name);
this.register(name);
},
function onError(error) {
console.log(error);
});
for
(result) => {
var name = JSON.stringify(result.first_name);
this.register(name);
},
(error) => {
console.log(error);
});
I have a Parse class Comment. Each Comment is submitted by a ParseUser and I wanna track in my parse user how many comments he has submitted, so I've created the following triggers in Parse Cloud Code:
/*
* ------------- AFTER SAVE
*/
Parse.Cloud.afterSave("Comment", function(request) {
//if it's the first save
if(!request.object.existed()) {
//increment the User's comments
query = new Parse.Query(Parse.User);
query.get(request.object.get("createdBy").id, {
success: function(user) {
user.increment("comments");
user.save();
}, error: function(error) {
console.log("Error searching the User");
}
});
}
});
/*
* ------------- AFTER DELETE
*/
Parse.Cloud.afterDelete("Comment", function(request) {
//decrement the User's comments
console.log("The user who submitted the comment has the id: " + request.object.get("createdBy").id);
query = new Parse.Query(Parse.User);
query.get(request.object.get("createdBy").id, {
success: function(user) {
console.log("Retrieved the user. He has username: " + user.get("username"));
user.increment("comments", -1);
user.save();
}, error: function(error) {
console.log("Error searching the user - error afterDelete#Comment 2");
}
});
});
The problem is that the afterSave trigger works, but the afterDelete doesn't and I can't figure out why. I can retrieve the User because the two console.log show out which is the correct user, but I can't save it, after the increment(user, -1). Thanks in advance.
EDIT:
Here the User trigger:
/*
* ------------- BEFORE SAVE
*/
Parse.Cloud.beforeSave("User", function(request, response) {
var comments = request.object.get("comments");
if(comments == null || comments < 0)
request.object.set("comments", 0);
var itemSaved = request.object.get("itemSaved");
if(itemSaved == null || itemSaved < 0)
request.object.set("itemSaved", 0);
var username = request.object.get("username");
if(username.length < 6 || username.length > 20)
response.error("username must be longer than 6");
else {
response.success();
}
});
/*
* ------------- AFTER DELETE
*/
Parse.Cloud.afterDelete("User", function(request) {
query = new Parse.Query("Comment");
query.equalTo("createdBy", request.object.id);
query.find({
success: function(comments) {
Parse.Object.destroyAll(comments, {
success: function() {},
error: function(error) {
console.error("Error deleting related comments " + error.code + ": " + error.message);
}
});
},
error: function(error) {
console.error("Error finding related comments " + error.code + ": " + error.message);
}
});
});
Per Parse's documentation, "If you want to use afterDelete for a predefined class in the Parse JavaScript SDK (e.g. Parse.User), you should not pass a String for the first argument. Instead, you should pass the class itself."
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.