我试图实现一个向所注册的某些令牌发送推送通知的应用程序。
我遵循了这个指南:http://docs.ionic.io/docs/push-sending-push 我正在尝试以下代码:
var CribbioApp = angular.module('CribbioApp', []); //Nome dell'applicazione (definito in data-ng-app)
CribbioApp.controller(' CribbioController',功能($ scope,$ http){// Definizione del controller(definito in data-ng-controller) $ scope.invianotifica = function(){ window.alert(' Porta pazienza!');
// Define relevant info
var privateKey = 'AIzaSyBfCGRs5F_dEp2Qd3Fag3mYVP44k9X4r4c';
var tokens = ['coHMIQnnWwU:APA91bGqmSZpcrbfDm3Hx_E7Loq9Y78AEXRfOX1t_TZ2IQumszLyPGQhfche4X5N0DAqbQFLuTFVYRQ055M3U-G-JlGwPtEd4kj31xtT0jswfj-ATfOefsLWG2dfVaffb5dFHzJUplNd'];
var appId = '390838258677';
// Encode your key
var auth = btoa(privateKey + ':');
// Build the request object
var req = {
method: 'POST',
url: 'https://push.ionic.io/api/v1/push',
headers: {
'Content-Type': 'application/json',
'X-Ionic-Application-Id': appId,
'Authorization': 'basic ' + auth
},
data: {
"tokens": tokens,
"notification": {
"alert":"Hello World!"
}
}
};
// Make the API call
$http(req).success(function(resp){
// Handle success
console.log("Ionic Push: Push success!");
}).error(function(error){
// Handle error
console.log("Ionic Push: Push error...");
});
但是我收到了这个错误:
POST https://push.ionic.io/api/v1/push 403 (Forbidden)
我发现错误403,意味着令牌无效(正确???),但我确定它是有效的! 我该如何解决?