【发布时间】:2014-01-06 12:54:54
【问题描述】:
我已通过 GCM 注册了 android 设备,并且设备的注册 ID 已在 Windows azure 中注册,这为该设备提供了另一个唯一 ID。现在我的疑问是如何通过 Windows azure 提供的注册 ID(而不是 GCM 注册 ID)仅向一台设备发送通知?我被推荐到以下链接。http://msdn.microsoft.com/en-us/library/windowsazure/dn223273.aspx
在该链接中指定的 URL 如下所示。在这里,我知道命名空间、通知中心和消息,但我必须在哪里提供由 windows azure 提供的设备的唯一注册 ID,以便向该设备发送通知
https://{namespace}.servicebus.windows.net/{NotificationHub}/messages/?api-version=2013-08
我在java中使用过以下代码
String strAzureURL = "https://namespaceName.servicebus.windows.net/hubName/testMessage";
String strAzureRegistrationId = "Tag1";
String strSharedAccessSignature = "MySharedAccessSignature";
String strSharedAccessName = "MySharedAccessName";
String strAuthorizationToken = URLDecoder.decode(strSharedAccessName+":"+strSharedAccessSignature,"UTF-8");
String strAuthWrapFormat = "WRAP access_token=\""+strAuthorizationToken+"\"";
String info = null;
HttpClient client = new HttpClient();
try {
GetMethod method = new GetMethod(strAzureURL);
method.setRequestHeader("Authorization", strAuthWrapFormat);
method.setRequestHeader("ServiceBusNotification-Tags", strAzureRegistrationId);
method.setRequestHeader("ServiceBusNotification-Format", "gcm");
method.setRequestHeader("Audience","https://namespaceName.servicebus.windows.net");
client.executeMethod(method);
info = method.getResponseBodyAsString();
System.out.println("Response "+info);
} catch (UnknownHostException e1) {
e1.printStackTrace();
throw e1;
}
现在我收到以下错误。
Response <Error><Code>401</Code>
<Detail>MissingAudience: The provided token does not specify the 'Audience'..TrackingId:75c1d492-3ddf-4d88-84b7-1c2f07d9623b_G5,TimeStamp:1/8/2014 9:57:39 AM</Detail>
</Error>
感谢您的帮助!
【问题讨论】:
标签: android windows azure google-cloud-messaging