Я использую MS graph, чтобы создать приложение для отправки события встречи с вложениями. Я могу отправить событие и вложение, но вложение не отправляется в пункт назначения, но я могу видеть мои отправленные события. Я хотел бы добавить вложение вместе с событием.
# def for event
def createmeet(access_token, subject, body, datetimestart, datetimeend, location, email):
createmeet_url = graph_endpoint.format ('/me/events') # /me/messages/{id}/send
hora = datetime.datetime.now()
data = {
"subject": subject,
"body": {
"contentType": "text",
"content": body,
},
"start": {
"dateTime": datetimestart,
"timeZone": "UTC"
},
"end": {
"dateTime": datetimeend,
"timeZone": "UTC"
},
"location":{
"displayName":location
},
"attendees": [
{
"emailAddress": {
"address":email
#"name": "Samantha Booth"
},
"type": "required"
}
]
}
r = make_api_call('POST', createmeet_url, access_token, data)
if (r.status_code == requests.codes.created):
print("Created event")
return r.json()
else:
print(r)
return "{0}: {1}".format(r.status_code, r.text)
# def for the attachment
def createattach(access_token, event_id, name, contentBytes, ContentType):
createattach_url = graph_endpoint.format ('/me/events/'+event_id+'/attachments/')
b64_content = base64.b64encode(open(name, 'rb').read())
mime_type = mimetypes.guess_type(name)[0]
data = {'@odata.type': '#microsoft.graph.fileAttachment',
'ContentBytes': b64_content.decode('utf-8'),
'ContentType': mime_type,
'name': name
}
r = make_api_call('POST', createattach_url, access_token, data)
if (r.status_code == requests.codes.created):
print("Created attach")
print(event_id)
return r.json()
#print(event_id)
else:
return "{0}: {1}".format(r.status_code, r.text)
#here is my view
def createmeet_view(request):
access_token = get_access_token(request, request.build_absolute_uri(reverse('app:gettoken')))
# If there is no token in the session, redirect to home
if not access_token:
return HttpResponseRedirect(reverse('app:home'))
else:
subject=request.POST.get('subject')
body=request.POST.get('body')
datetimestart=request.POST.get('datetimestart')
datetimeend=request.POST.get('datetimeend')
email=request.POST.get('email')
location=request.POST.get('location')
attachments = True #('name')
contentBytes = True
ContentType = True
if subject and body and datetimestart and datetimeend and location and email:
event = createmeet(access_token, subject, body, datetimestart, datetimeend, location, email)
if attachments:
#print(event["id"])
created_attachment = createattach(access_token, event["id"], name ="C:/media/media/name.jpeg", contentBytes=contentBytes, ContentType=ContentType)
return render(request, 'pages/createmeet.html')
Кто-нибудь знает, что я здесь делаю неправильно? Спасибо!