你能帮我使用RingCentral Fax API吗?我需要 C# 代码来下载通过传真发送的附件。我正在使用沙盒帐户,并在 API 资源管理器中找到了此 API:
/restapi/v1.0/account/{accountId}/extension/{extensionId}/message-store/{messageId}/content/{attachmentId}
使用RingCentral C-Sharp SDK可以下载二进制内容,如下所示:
RestClient rc = new RestClient("ClientID", "ClientSecret", false);
await rc.Authorize("username", "extensionNumber", "password");
...
var extension = rc.Restapi().Account().Extension();
var messages = response.records;
// fax
var message = messages.Where(m => m.type == "Fax" && m.messageStatus != "SendingFailed" && m.attachments != null && m.attachments.Length > 0).Skip(3).First();
var content = await extension.MessageStore(message.id).Content(message.attachments[0].id).Get();
System.IO.File.WriteAllBytes("filename.ext", content.data);
从此处查看详细的示例代码
您可以使用WebClient
类下载。 示例代码供您参考。
法典:
WebClient client = new WebClient();
client.Headers.Add("Authorization", "Bearer Access_Token");
File.WriteAllBytes(@"Path To Download", client.DownloadData(URL));
注意:网址restapi/v1.0/account/AccountID/extension/extension ID/message-store/Message ID/content/Message ID