C# 谷歌GCM不匹配Senderid
我一直在尝试制作一个简单的推送通知测试应用程序,但我似乎无法找到正确的凭据来使用 根据我的发现,我相信我所需要的只是一个PushNotification服务器密钥、api项目编号和设备的注册ID。我从Google开发控制台获得了服务器密钥: 控制台中此处的我的项目API编号: 顺便说一下,这是我的仪表板URL中“project=api project-”后面的数字 最后,我从InstanceID对象获得的设备注册ID:C# 谷歌GCM不匹配Senderid,c#,android,google-cloud-messaging,C#,Android,Google Cloud Messaging,我一直在尝试制作一个简单的推送通知测试应用程序,但我似乎无法找到正确的凭据来使用 根据我的发现,我相信我所需要的只是一个PushNotification服务器密钥、api项目编号和设备的注册ID。我从Google开发控制台获得了服务器密钥: 控制台中此处的我的项目API编号: 顺便说一下,这是我的仪表板URL中“project=api project-”后面的数字 最后,我从InstanceID对象获得的设备注册ID: var instanceID = InstanceID.GetInstan
var instanceID = InstanceID.GetInstance (this);
var token = instanceID.GetToken (
"68********12", GoogleCloudMessaging.InstanceIdScope, null);
Log.Info ("RegistrationIntentService", "GCM Registration Token: " + token);
SendRegistrationToAppServer (token);
Subscribe (token);
虽然我相信应用程序永远不会达到GCM试图向应用程序发送消息的程度,但我相信问题存在于发送消息的应用程序和GCM服务器之间。这就是我所需要的,不是吗
至于向应用程序发送推送消息的代码(通知我错误的代码),我使用的是PushSharp库v3。代码如下所示:
List<string> registrationIDs = new List<string> ();
registrationIDs.Add ("APA*************************************HnHb");
var config = new GcmConfiguration ("AIza**********w8");
var broker = new GcmServiceBroker (config);
broker.OnNotificationFailed += (GcmNotification notification, AggregateException exception) => {
exception.Handle(ex => {
/*Ex handling*/
return true;
});
};
broker.OnNotificationSucceeded += (notification) => {
Console.WriteLine ("Notification Sent!");
};
broker.Start ();
string message = "";
while (message != "quit"){
Console.Clear ();
Console.WriteLine ("Message to be sent (\"quit\" to quit):\n");
message = Console.ReadLine ();
broker.QueueNotification (new GcmNotification () {
RegistrationIds = registrationIDs,
Notification = JObject.Parse ("{\"alert\":\"" + message + "\",\"badge\":7}")
});
}
broker.Stop ();
List registrationIDs=newlist();
注册ID.Add(“APA***************************************************************************HnHb”);
var配置=新的GCM配置(“AIza*************w8”);
var broker=新的GcmServiceBroker(配置);
broker.OnNotificationFailed+=(GcmNotification通知,AggregateException异常)=>{
异常句柄(ex=>{
/*交货处理*/
返回true;
});
};
broker.onNotificationSuccessed+=(通知)=>{
Console.WriteLine(“已发送通知!”);
};
broker.Start();
字符串消息=”;
while(消息!=“退出”){
Console.Clear();
Console.WriteLine(“要发送的消息(\'quit\'要退出):\n”);
message=Console.ReadLine();
broker.QueueNotification(新的GcmNotification(){
注册ID=注册ID,
Notification=JObject.Parse(“{\”警报\“:\”+消息+“\”,\”徽章\“:7}”)
});
}
broker.Stop();
在
broker.OnNotificationFailed
行中,我将从GCM服务器获取不匹配的SenderId
。你知道我遗漏了什么吗?你用什么来生成InstanceID令牌?项目id号表示什么库?我用Xamarin编码,它将所有Android代码映射到C#,所以技术上我使用标准Android代码。因此,我的理解是,我使用的是:通常不匹配的SenderId表示用于向设备发送消息的API密钥来自与用于生成InstanceID令牌的API密钥不同的项目。您能否确认GcmConfiguration中使用的API密钥与GetToken中使用的id来自同一个项目