在SendGrid统计数据上未经授权

时间:2016-11-02 16:29:13

标签: c# sendgrid

我正在尝试获取所有子用户的每个电子邮件统计信息指标的总计。

但是我收到了一条授权的必填信息:

我无法弄清楚问题是什么。我在网上引用了sendgrid api,这应该是正确的格式。

https://github.com/sendgrid/sendgrid-csharp

Unauthorized {"errors":[{"field":null,"message":"authorization
required"}]} Connection: keep-alive Access-Control-Allow-Methods:
HEAD, GET, PATCH, PUT, POST, OPTIONS, DELETE Access-Control-Max-Age:
21600 Access-Control-Expose-Headers: Link Access-Control-Allow-Origin:
* Access-Control-Allow-Headers: AUTHORIZATION, Content-Type, On-behalf-of, x-sg-elas-acl Content-Security-Policy: default-src
https://api.sendgrid.com; frame-src 'none'; object-src 'none'
X-Content-Type-Options: nosniff Strict-Transport-Security:
max-age=31536000 Date: Wed, 02 Nov 2016 16:25:29 GMT Server: nginx

以下是我正在使用的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SendGrid;
using Newtonsoft.Json; // You can generate your JSON string yourelf or with another library if you prefer
using System.Web.Script.Serialization;
using SendGrid.Helpers.Mail;

namespace SendGridSubStats
{
    class Program
    {
        static void Main(string[] args)
        {
            Execute().Wait();

        }

        static async Task Execute()
        {
            string apiKey = Environment.GetEnvironmentVariable("APIKEY_GOES_HERE", EnvironmentVariableTarget.User);
            dynamic sg = new SendGridAPIClient(apiKey);

            //  Retrieve the totals for each email statistic metric for all subusers.
            // GET /subusers/stats/sums

                        string queryParams = @"{
                              'aggregated_by': 'day', 
                              'end_date': '2016-04-01', 
                              'limit': 1, 
                              'offset': 1, 
                              'sort_by_direction': 'asc', 
                              'sort_by_metric': 'test_string', 
                              'start_date': '2016-01-01'
                            }";
                        dynamic response = await sg.client.subusers.stats.sums.get(queryParams: queryParams);
            Console.WriteLine(response.StatusCode);
            Console.WriteLine(response.Body.ReadAsStringAsync().Result);
            Console.WriteLine(response.Headers.ToString());
            Console.ReadLine();
        }
    }
}

0 个答案:

没有答案