Stackmob在注册设备时发出401错误

时间:2012-06-25 13:33:55

标签: stackmob

我正在使用用户名和设备令牌将设备注册到stackmob。我从c2dn获取有效令牌,然后将其存储到该用户的db中,然后在注册到stackmob时我使用这些参数。在开发环境中,它的工作正常,但同一段代码在注册设备时给出了401。请在此建议我。

以下代码如下:

public String registerWithNotificationServiceProvider(final String userName, final String deviceToken)        throws UserException 

         {
    if (userName.isEmpty() || deviceToken.isEmpty()) {
        throw new UserException(ResponseCodes.STATUS_BAD_REQUEST, "User Name or device      token is null",## Heading ##                    "label.invalid.user.device.details");
    }
    StackMobRequestSendResult deviceRegisterResult = null;
    deviceRegisterResult = StackMob.getStackMob().registerForPushWithUser(userName, deviceToken,
            new StackMobRawCallback() {
                @Override
                public void done(HttpVerb requestVerb, String requestURL,
                        List<Map.Entry<String, String>> requestHeaders, String requestBody,
                        Integer responseStatusCode, List<Map.Entry<String, String>> responseHeaders,
                        byte[] responseBody) {
                    String response = new String(responseBody);
                    logger.info("request Body is " + requestBody);
                    logger.info("request Url is " + requestURL);
                    for(Map.Entry<String, String> entry : requestHeaders){
                        logger.info("Request Header is " + entry.getKey());
                        logger.info("Request Header content is " + entry.getValue());
                    }
                    for(Map.Entry<String, String> entry : responseHeaders){
                        logger.info("Response Header is " + entry.getKey());
                        logger.info("Response Header content is " + entry.getValue());
                    }
                    logger.info("response while  registering the device is  " + response);
                    logger.info("responseCode while registering device " + responseStatusCode);
                }
            });
    String status = null;
    if (deviceRegisterResult.getStatus() != null) {
        status = deviceRegisterResult.getStatus().name();
        logger.debug("For user : " + userName + " Status for registering device is " + status);
    }
    if (Status.SENT.getStatus().equalsIgnoreCase(status)) {
        return Status.SUCCESS.getStatus();
    } else {
        return Status.FAILURE.getStatus();
    }

}

1 个答案:

答案 0 :(得分:1)

当您使用api密钥和密钥设置StackMob对象时,您是否记得将apiVersion 1与您的生产密钥和密钥一起使用?这是最可能的问题。

StackMobCommon.API_KEY = KEY;
StackMobCommon.API_SECRET = SECRET;
StackMobCommon.USER_OBJECT_NAME = "user";
StackMobCommon.API_VERSION = 1; //! 0 for dev, 1 for production

如果不起作用也设置     。StackMob.getStackMob()getLogger()setLogging(真)。 在开头并发布结果日志