使用Python、Django和Graph更新联系人
我试图在使用Django创建的个人资料页面中使用Python和Microsoft Graph更新联系人 我可以访问联系人并获取所需的所有数据,但我无法确定如何更新字段 我能找到的唯一信息是在Graph网站上,但我不知道如何将其转换为可用代码:使用Python、Django和Graph更新联系人,python,django,graph,microsoft-graph-api,Python,Django,Graph,Microsoft Graph Api,我试图在使用Django创建的个人资料页面中使用Python和Microsoft Graph更新联系人 我可以访问联系人并获取所需的所有数据,但我无法确定如何更新字段 我能找到的唯一信息是在Graph网站上,但我不知道如何将其转换为可用代码: PATCH PATCH https://graph.microsoft.com/beta/me/contacts/ Content-type: application/json { "title": "Mr", "givenName": "Ste
PATCH PATCH https://graph.microsoft.com/beta/me/contacts/
Content-type: application/json
{
"title": "Mr",
"givenName": "Steve"
}
我假设有一种方法可以把它作为一个简单的链接放在一起,但我无法解决它。我尝试了以下方法:
PATCH https://graph.microsoft.com/beta/me/contacts/{id}/title/Mr
PATCH https://graph.microsoft.com/beta/me/contacts/{id}/title:Mr
PATCH https://graph.microsoft.com/beta/me/contacts/{id}/title/$value==Mr
但它们都会产生错误
微软网站上没有关于Python的教程,而且很难找到关于Python的任何信息。希望有人能帮忙
干杯
!!!!!!!!!!!!!更新
这是我目前的代码,但遗憾的是它仍然不起任何作用:
在my views.py中:
def profile(request):
if request.session['has_id']==False:
contact_id = request.session['contact_id'] = request.POST.get('edit')
request.session['has_id'] = True
else:
contact_id = request.session['contact_id']
context = ct.profile(request,id=request.session.get('contact_id'),init=initialize_context,get_tok=get_token)
if request.method=="PATCH":
ct.update(contact_id,'title',request.PATCH.get('title'))
return render(request, 'tutorial/profile.html', context)
和我的更新程序:
def update(id,key,value):
url = '{}/me/contacts/{}'.format(graph_url,id)
payload = {key : value}
head = {
"Content-type" : "application/json",
}
requests.patch(url=url,data=payload,headers=head)
终于解决了,我想我昨天试过类似的东西,但显然没有 下面是如何做到这一点 views.py
def profile(request):
if request.session['has_id']==False:
contact_id = request.session['contact_id'] = request.POST.get('edit')
request.session['has_id'] = True
else:
contact_id = request.session['contact_id']
context = ct.profile(request,id=request.session.get('contact_id'),init=initialize_context,get_tok=get_token)
if request.method=="PATCH":
ct.update(contact_id,'title',request.PATCH.get('title'))
return render(request, 'tutorial/profile.html', context)
联系人_helper.py:
def update(token,id,key,value):
graph_client = OAuth2Session(token=token)
url = '{}/me/contacts/{}'.format(graph_url,id)
payload = {key : value}
graph_client.patch(url,data=json.dumps(payload),headers={'Content-type': 'application/json'})
显然,如果您正在查看此信息,您可能已经设置了auth_helper.py和graph_helper.py,但如果尚未设置,则应浏览Microsoft graph网站并按照以下说明操作:
终于解决了,我想我昨天尝试过类似的东西,但显然没有 下面是如何做到这一点 views.py
def profile(request):
if request.session['has_id']==False:
contact_id = request.session['contact_id'] = request.POST.get('edit')
request.session['has_id'] = True
else:
contact_id = request.session['contact_id']
context = ct.profile(request,id=request.session.get('contact_id'),init=initialize_context,get_tok=get_token)
if request.method=="PATCH":
ct.update(contact_id,'title',request.PATCH.get('title'))
return render(request, 'tutorial/profile.html', context)
联系人_helper.py:
def update(token,id,key,value):
graph_client = OAuth2Session(token=token)
url = '{}/me/contacts/{}'.format(graph_url,id)
payload = {key : value}
graph_client.patch(url,data=json.dumps(payload),headers={'Content-type': 'application/json'})
显然,如果您正在查看此信息,您可能已经设置了auth_helper.py和graph_helper.py,但如果尚未设置,则应浏览Microsoft graph网站并按照以下说明操作: