we already implemented push notification concept using android but we are trying to send push notification using web application to mobile
here is my code
function authentication() {
debugger;
Parse.$ = jQuery;
// Initialize Parse with your Parse application javascript keys
Parse.initialize("App key",
"javascript key");
debugger;
var pushQuery = new Parse.Query(Parse.Installation);
debugger;
pushQuery.containedIn("channels", true);
Parse.Push.send({
where: pushQuery,
data: {
alert: "Your push message here!"
}
}, {
success: function() {
debugger;
response.success("pushed");
}, error: function(error) {
reponse.error("didn't push");
debugger;
}
})
We are got error
POST https://api.parse.com/1/push 400 (Bad Request)
Uncaught ReferenceError: reponse is not defined
We followed this link & Docs of parse.com
Plz guide to us
Related
I am trying to develop an add-in for Microsoft Word Online. I am using Office.context.auth.getAccessTokenAsync call to get access token of a user, but it throws
error: Object {
name: "API Not Supported",
message: "This browser does not support the requested API.",
code: 5009
}
status: "failed"
Can anyone help?
Here is code that I am using to get Token.
"use strict";
(function() {
// The initialize function is run each time the page is loaded.
Office.initialize = function(reason) {
$(document).ready(function() {
// Use this to check whether the API is supported in the Word client.
if (Office.context.requirements.isSetSupported("WordApi", 1.1)) {
// Do something that is only available via the new APIs
$("#buttonPressed").click(getToken);
} else {
// Just letting you know that this code will not work with your version of Word.
$("#supportedVersion").html("This code requires Word 2016 or greater.");
}
});
};
function getToken() {
if (Office.context.requirements.isSetSupported("IdentityAPI", 1.1)) {
console.log("Yes Identity API is supported");
// code to request an SSO token.
Office.context.auth.getAccessTokenAsync(function(result) {
if (result.status === "succeeded") {
var token = result.value.accessToken;
console.log(token);
} else {
console.log("Error obtaining token", result.error);
}
});
} else {
console.log(" ID API not supported.");
}
}
})();
My manifest code placed above </VersionOverrides>
<WebApplicationInfo>
<Id> <My App ID is here> </Id>
<Resource>api://localhost:3000/<My App ID is here></Resource>
<Scopes>
<Scope>Files.Read.All</Scope>
<Scope>offline_access</Scope>
<Scope>openid</Scope>
<Scope>profile</Scope>
</Scopes>
</WebApplicationInfo>
Also tried
<Resource>https://localhost:3000</Resource>
in above code.
I need to send a Push notification after a class is updated by the user, the push notification is working from the Dashboard.
I added this code to my Cloud Code, i can see the logs with the success message, but the notification is not being sent to the user, on the past notification, it shows that was sent, but the audience is Everyone, but pushs sent is 0, this is my Cloud Code
Parse.Cloud.afterSave("Class", function(request, response) {
var inObject = request.object;
if (inObject.get("isLost")){
console.log("inObject is lost");
var targetUser = new Parse.User();
targetUser.id = inObject.get("UserID");
var query = new Parse.Query(Parse.Installation);
query.equalTo("user", targetUser);
Parse.Push.send({
where: query,
data: {
alert: "InObject",
badge: "Increment",
message: "Testando"
}
}, {
success: function() {
// Push was successful
console.log("success");
},
error: function(error) {
// Handle error
console.log("error: "+error.code+" message "+error.message);
throw "Got an error " + error.code + " : " + error.message;
},
useMasterKey: true
});
}
});
I tried to do the double query as the post link, but no success, i loged the user ID and is the same as show on my Installation in the Dashboard.
If i click the Push notification for more details this is the Target that it shows:
Target details from push
Edit
Save code for that class(it's in java):
ParseObject object = new ParseObject(Class.class.getSimpleName());
object.put(NAME, getName());
object.put(UUID, getUUID());
object.put(ICON_ID, getIconID());
object.put(ADDRESS, getAddress());
object.put(ID1, iD1.toString());
object.put(ID2, iD2.toString());
object.put(ID3, iD3.toString());
object.put(IS_LOST, getIsLost());
object.put(USER, parseUserID);
object.put(DISTANCE, getDistance());
object.put(LATITUDE, getLatitude());
object.put(LONGITUDE, getLongitude());
object.saveEventually();
The parseID is being generated by the ParseUser.getCurrentUser().getObjectID();
So, after trying this in a lot of ways, i ended up creating a relation between my object and the ParseUser object, this solved the issue, still i don't know why can't i just save the UserID, but my problem is solved now.
I am using smsCordova plugin to send sms from my ionic application but getting the error that "SMS is not defined".
I had used the cordovaSms plugin in $ionicPlatform.ready() function.
Here is my code which i am using to send the SMS :-
//use verifyNumber service
verifyNumberService.verify()
.then(
function (result) {
if (result == "Successfully data save...") {
//alert and navigate to profile Info state
$ionicPopup.alert({
title: 'Registered',
template: 'Thanks For Signup'
});
$ionicPlatform.ready(function() {
alert("in device ready function")
sendOtp();
});
$state.go('profileInfo');
}
This is the function to sendOtp() :-
function sendOtp() {
alert("inside send otp");
$cordovaSms
.send('+919765293765', "Hi there",{})
.then(function () {
// Success! SMS was sent
alert("success")
console.log('Success');
}, function (error) {
// An error occurred
alert("error");
console.log(error);
});//then
alert("send otp");
}
Azhar Khan,
If we wants to use the send sms request in cordova, then
1. we need to install this plugin in you app :
cordova plugin add https://github.com/cordova-sms/cordova-sms-plugin.git
2.Need to add that plugin instance($cordovaSms) in Controler function :
.controller('ThisCtrl', function($cordovaSms) {
});
Now we can send the sms throw that plugin using this code inside you controler :
document.addEventListener("deviceready", function () {
$cordovaSms.send('mobile_number', 'SMS Message', options)
.then(function() {
alert(SMS sent )
}, function(error) {
alert(Problem in sending SMS)
});
});
Thats all we need for sending SMS to any number in ionic
Have a happy code day.
I'm looking to create an html/javascript based form that posts an article to my website and at the same time will make a push notification through my iOS and future android app. I'd rather do an all in one rather than posting it on the website then doing the push through Parse's website.
I'm just not exactly sure how to go about it if it's even possible.
Yes its possible you have to make the HTML form. if your form name is as follows
<form id="postArticle">
<input type="text" it="articleID" name="article">
<input type="submit" value="Submit">
</form>
you can JS code to submit data and save data in parse and send push notifications to selected devices
$("#postArticle").submit(function(e) {
var TestObject = Parse.Object.extend("Articles");
var requestObj = new TestObject();
requestObj.set('startTime',$("#articleID").val();
requestObj.save({
success: function(object) {
//on success of inserting data to parse we will send notifications to device
Parse.Push.send({
channels: "yourChannel name",
deviceType:"ios" , //device types android or iOS
data: {
alert: "New Articles submitted",
badge: "Increment",
sound: "default",
}
}, {
success: function() {
// Push was successful
alert("Your request has been send");
},
error: function(error) {
// Handle error
//console.log(error);
alert(error.message);
}
});
},
error:function(error){
alert(error);
})
}
The user will click on a button that will invoke the Parse Cloud function sendText()
I've tried both Live Twilio and Testing Twilio accSID and authToken
I first initialize my Twilio by:
var Twilio = require('twilio');
Twilio.initialize('accountSid', 'authToken'); //put in my corresponding <<
then I set the Parse function by:
Parse.Cloud.define('sendText', function(request, response) {
Twilio.sendSMS({
From: '+1234567890', //From Number
To: "+0987654321", //To Number
Body: "Start using Parse and Twilio!" //Message <<
}, {
success: function(httpResponse) { response.success("SMS sent!"); },
error: function(httpResponse) { response.error("Uh oh, something went wrong"); }
});
}
It would be great to have someone tell me if something here is wrong or if there are other approaches in sending SMS through Twilio via Parse Cloud.
On the SMS Summary on Twilio, it does not even know any SMS being sent out.
Going on...
The button that calls this cloud function is:
<button type="button" class="page-scroll btn btn-xl" onclick="saveData()">CONFIRM</button>
and the js function that is called saveData() is:
function saveData() {
booking.save({
something: something,
}, {
success: function (booking) {
window.location.href = 'final.php';
Parse.Cloud.run('sendText',
{
something: something
});
},
error: function (booking, error) {
alert('Failed to save');
}
});
}
NO ERROR LOG
Twilio developer evangelist here.
You seem to be using an old Parse module which is no longer supported by us. The new module however uses a newer version of our Node module.
Some documentation for it can be found here
It also has some sample code to do what you're trying to do.
// Require and initialize the Twilio module with your credentials
var client = require('twilio')('ACCOUNT_SID', 'AUTH_TOKEN');
// Send an SMS message
client.sendSms({
to:'+0987654321',
from: '+1234567890',
body: 'Hello world!'
}, function(err, responseData) {
if (err) {
console.log(err);
} else {
console.log(responseData.from);
console.log(responseData.body);
}
}
);
I think you will find your SMS will be sent using this version of the code. Notice how the initialization is different.