【发布时间】:2016-10-04 17:45:00
【问题描述】:
我正在使用 Dailymotion API 构建应用 https://developer.dailymotion.com/ 使用官方 python sdk https://github.com/dailymotion/dailymotion-sdk-python 并简单地编写视频 CRUD(创建、读取、更新、删除)。 Create、Read、Delete 已成功完成,但遇到 API 关于“更新”的奇怪响应。
这是我的 Django 项目中代码的简化 sn-p,
def update(request, video_id):
user = request.user
video = get_object_or_404(Video, pk=video_id)
file_path = # define file_path from uploaded file object
input_title = # define input_title from post request
input_description = # define input_description from post request
d = get_dailymotion_d(user)
if d == 'revoked':
# do actions of logout and delete the user
try:
# get url for upload with the file_path on my server
url = d.upload(file_path)
# update
response = d.post('/video/' + video.dailymotion_video_id, {'url': url, 'title': input_title, 'description': input_description, 'published': 'true', 'channel': 'creation'})
# delete the video from my sever
video.file_field.delete()
return redirect('/videos')
except Exception as e:
print(e.args)
print('update failed..!')
# delete the video from my server
video.file_field.delete()
return redirect('/videos')
def get_dailymotion_d(user):
d = dailymotion.Dailymotion()
d.set_grant_type('token', api_key=settings.DAILYMOTION_API_KEY, api_secret=settings.DAILYMOTION_API_SECRET, scope=['email', 'userinfo', 'manage_videos'], info={'redirect_uri': settings.DAILYMOTION_REDIRECT_URI})
# get credentiaols from database
access_token = user.dailymotionuser.access_token
expires = user.dailymotionuser.expires
refresh_token = user.dailymotionuser.refresh_token
session_params = {'access_token': access_token, 'expires': expires, 'refresh_token': refresh_token}
# set the credentials
d._session_store.set(session_params)
# check if the user revoked or not
try:
force_refreshed_access_token = d.get_access_token(force_refresh=True)
except dailymotion.DailymotionAuthError as e:
print(e.args[0])
return 'revoked'
# get valid access token
valid_access_token = d.get_access_token()
# update database with the valid access token
DailymotionUser.objects.filter(user=user).update(access_token=valid_access_token, expires=expires, refresh_token=refresh_token)
# prepare dic of the valid access token
valid_access_token_dic = {'access_token': valid_access_token}
# set the valid access token
d._session_store.set(valid_access_token_dic)
return d
但更新失败,除了 title 字段并显示以下消息,
'access_forbidden:您不能更改现有的视频源。'
来自文档,
access_forbidden:当用户无权访问数据时抛出(例如,缺少访问某些字段所需的范围)。
但我确信该权限具有manage_videos 范围,这是一个足以更新现有视频源的范围,因为文档说,
manage_videos:允许修改或删除用户上传的视频并发布新视频。
如上所述,
只有视频的title 字段正确更新为input_title。
感谢阅读,我仔细研究了他们的文档,但还是不明白这个回复。
【问题讨论】:
标签: dailymotion-api