0
ASP.NET MVC를 사용하여 프로그래밍 방식으로 마지막 이메일의 첨부 파일을 다운로드하고 싶습니다.GMAIL API .NET 잘못된 첨부 토큰
여기에서 찾을 수있는 유일한 권한은 "https://www.googleapis.com/auth/gmail.readonly"이며 "모든 리소스와 메타 데이터 읽기 - 쓰기 작업 없음"을 허용합니다. 자료 : 지금까지,이 내 코드의 예입니다
$exception
{"Google.Apis.Requests.RequestError
Invalid attachment token [400]
Errors
[Message[Invalid attachment token]
Location[ - ] Reason[invalidArgument]
Domain[global]\r\n]\r\n"}
:
static string[] Scopes = { GmailService.Scope.GmailReadonly };
public ActionResult Login()
{
UserCredential credential;
var diskPath = Server.MapPath("~");
using (var stream = new FileStream(diskPath + "/Content/client_secret.json", FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None).Result;
}
// Create Gmail API service.
var service = new GmailService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
var resp = service.HttpClient.GetStringAsync("https://www.googleapis.com/gmail/v1/users/me/messages?q=\"has:attachment\"").Result;
var root = JsonConvert.DeserializeObject<ListMessagesResponse>(resp);
foreach (var msg in root.Messages)
GetAttachments(service, msg.Id);
return View();
}
public static void GetAttachments(GmailService service, String messageId)
{
var message = service.Users.Messages.Get("me", messageId).Execute();
var parts = message.Payload.Parts;
foreach (var part in parts)
{
if (!String.IsNullOrEmpty(part.Filename))
{
var attachPart = service.Users.Messages.Attachments.Get("me", messageId, part.PartId).Execute();
var file = Convert.FromBase64String(attachPart.Data);
System.IO.File.WriteAllBytes(part.Filename, file);
}
}
}
(https://developers.google.com/gmail/api/auth/scopes)
문제는 내가 액세스하려고 할 때 나는 오류가 첨부입니다 다음과 같은 오류 메시지가 나타납니다.
var attachPart = service.Users.Messages.Attachments.Get("me", messageId, part.PartId).Execute();
다른 범위가 있습니까? 첨부 파일을 넣어야합니까? 또는 일부 작업 후에 토큰을 새로 고쳐야합니까? 이미 내 Google+ 프로필에서 앱을 제거하고 다시 추가하려고했습니다.