我怎么会不断收到“请求失败,响应代码为401"?试图通过城市飞艇推进时? [英] How come I keep getting a "Request failed with response code 401" when trying to push via Urban Airship?

查看:118
本文介绍了我怎么会不断收到“请求失败,响应代码为401"?试图通过城市飞艇推进时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经进行了两次,三次和四次检查,以确保我具有要传递的正确的主密钥.我的参数也直接从UA网站获取,所以不是这样.有人在这里看到我在做什么错吗?

Parse.Cloud.define("sendPush", function(request, response) {

  var Buffer = require('buffer').Buffer;

  var parameters = {
    "audience" : "all",
     "device_types" : "all",
     "notification" : {
         "alert" : "Hello from Urban Airship."
     }
  };

  var params = JSON.stringify(parameters);

  Parse.Cloud.httpRequest({
    url: "https://go.urbanairship.com/api/push/",
    method: 'POST',
    headers: {
        "Content-Type" : "application/json",
        "Authorization" : 'Basic ' + new Buffer('MASTER_KEY').toString('base64'),
        "Accept" : "application/vnd.urbanairship+json; version=3;"
    },
    body: params,
    success: function(httpResponse) {
        response.error(httpResponse);
    },
    error: function(httpResponse) {
      response.error('Request failed with response code ' + httpResponse.status);
    }
  });

});

我也尝试添加APP_SECRET:

"Authorization" : 'Basic ' + new Buffer('APP_SECRET':'MASTER_KEY').toString('base64'),

解决方案

从代码示例中尚不清楚您是否在请求中包含了应用程序密钥.向Urban Airship发出的API请求使用HTTP基本身份验证.用户名部分是应用程序密钥,密码部分在这种情况下是主密钥.应用程序密码仅限于安全性较低的API,并且可在分布式应用程序中使用.发送消息和其他服务器API请求需要主密码.

城市飞艇为对常见API问题进行故障排除提供了指南. /p>

I have double, triple, and quadruple checked that I have the right master key that I'm passing. My parameters are taking directly from the UA website also so it can't be that. Anyone see what I'm doing wrong here???

Parse.Cloud.define("sendPush", function(request, response) {

  var Buffer = require('buffer').Buffer;

  var parameters = {
    "audience" : "all",
     "device_types" : "all",
     "notification" : {
         "alert" : "Hello from Urban Airship."
     }
  };

  var params = JSON.stringify(parameters);

  Parse.Cloud.httpRequest({
    url: "https://go.urbanairship.com/api/push/",
    method: 'POST',
    headers: {
        "Content-Type" : "application/json",
        "Authorization" : 'Basic ' + new Buffer('MASTER_KEY').toString('base64'),
        "Accept" : "application/vnd.urbanairship+json; version=3;"
    },
    body: params,
    success: function(httpResponse) {
        response.error(httpResponse);
    },
    error: function(httpResponse) {
      response.error('Request failed with response code ' + httpResponse.status);
    }
  });

});

I've also tried adding in APP_SECRET:

"Authorization" : 'Basic ' + new Buffer('APP_SECRET':'MASTER_KEY').toString('base64'),

解决方案

It's not clear from your code sample if you are including the app key in your request. API requests to Urban Airship use HTTP basic authentication. The username portion is the application key and the password portion in this case is the master secret. The application secret is restricted to lower-security APIs and is for use in the distributed application. The master secret is needed for sending messages and other server API requests.

Urban Airship provides a guide for troubleshooting common API issues.

这篇关于我怎么会不断收到“请求失败,响应代码为401"?试图通过城市飞艇推进时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆