【问题标题】:GMail API Error: Path "{userId}/messages/send" misses a "userId" parameter. Is this a bug?GMail API 错误:路径“{userId}/messages/send”缺少“userId”参数。这是一个错误吗?
【发布时间】:2020-04-06 05:30:03
【问题描述】:

我正在尝试从 Unity3D 脚本中通过 .NET API for GMail 发送电子邮件。不幸的是,我遇到了一些麻烦。每当我在游戏中按“R”键时,都会调用以下代码。

//MEMBERS INCLUDED AT TOP OF CLASS
//TextAsset credFile;
//static String AppName = "Redacted-Appname";
//
//List<string> Scopes = new List<string>() { "GMAIL_SEND" };



if (Input.GetKeyDown(KeyCode.R))
    {
        UserCredential emailerCredential;

        //Create Credential
        using (MemoryStream credStream = new MemoryStream(credFile.bytes))
        {
            string credPath = "token.json";
            emailerCredential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(credStream).Secrets,
                Scopes,
                "myDoubleCheckedEmailAddress@redacted.com",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;
        }

        //Create Service using credential
        GmailService service = new GmailService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = emailerCredential,
            ApplicationName = AppName
        });

        //Create Mail Message
        MailMessage message = new MailMessage(
            "myDoubleCheckedEmailAddress@redacted.com",
            "DoubleCheckedTOEmailAddress@redacted.com",
            "Test Email Using GMail API",
            "This is a test of the emergency llama system.");

        //Create Gmail Message
        Message emailmsg = new Message();
        //ConvertMail Message to URL Encoded Base64 string and feed it into Gmail message
        emailmsg.Raw = HttpUtility.UrlEncode(Convert.ToBase64String(Encoding.ASCII.GetBytes(message.ToString())));
        string userId = "myDoubleCheckedEmailAddress@redacted.com";
        service.Users.Messages.Send(emailmsg, userId).Execute();
    }

由于这段代码,我最终得到以下异常:

ArgumentException:路径“{userId}/messages/send”缺少“userId” 参数 UnityLoader.js:1043 参数名称:{userId}/messages/send UnityLoader.js:1043 在 Google.Apis.Requests.RequestBuilder.BuildRestPath () [0x00000] 在 :0 UnityLoader.js:1043 --- 结束 来自先前引发异常的位置的堆栈跟踪 --- UnityLoader.js:1043 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] 在 :0

我相信请求构建器正在将 {userId} 构建到 REST 请求中,而不是插入实际的用户名。寻找有更多经验的人来确认/否认这一点。这是一个错误,还是我做错了?

假设这是一个错误,我将在 GMail.Net API github 上发布它:https://github.com/googleapis/google-api-dotnet-client/issues

【问题讨论】:

  • 看起来它正在读取某种字典来进行插值,但字典没有 userID 键。
  • 回应已删除评论 这里的Message 类来自Google.Apis.Gmail.v1.Data。我也尝试将 Message 更改为 var(隐式类型)并得到相同的结果。
  • 尝试使用Scopes = new List&lt;string&gt;() { GmailService.Scope.GmailSend };
  • @Ruzihm 感谢您的提示,但不幸的是,仍然没有骰子。我得到了完全相同的结果。更改后Scopes
  • 如果您认为这是一个错误,最好将其直接发布到 Google 的公共问题跟踪器 developers.google.com/issue-tracker。但在此检查之前: 1. 修改范围后,删除您在~/.credentials/*.json 中的凭据以启动新的授权流程。 2. 确保包含所有必要的库。 3. 看看你是否可以通过严格遵循示例来解决问题(developers.google.com/gmail/api/quickstart/dotnetdevelopers.google.com/gmail/api/v1/reference/users/messages/… - 范围为GmailService.Scope.GmailSend

标签: c# .net unity3d gmail gmail-api


【解决方案1】:

我将此作为错误报告发布到 Google Github 并记录在那里。然而,我被告知 Unity3D 不是受支持的平台,因此该问题的优先级较低。如果有人想解决这个问题,他们将不得不分支 repo。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多