2016-10-03 3 views
0

나는 공식 파이썬 SDK https://github.com/dailymotion/dailymotion-sdk-python 및 쓰기 비디오 CRUD (생성, 읽기, 업데이트, 삭제) 단지와 데일리 모션의 API https://developer.dailymotion.com/ 를 사용하여 응용 프로그램을 짓고 있어요. 만들기, 읽기, 삭제가 성공적으로 완료되었지만 "업데이트"에 대한 API의 이상한 응답이 발생했습니다. , 는 'access_forbidden 여기 Dailymotion API에서 기존 비디오를 대체하는 방법은 무엇입니까?

내 장고 프로젝트에 내 코드의 단순화 된 조각,

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 : 사용자가 (예를 들어, 특정 필드에 액세스하기 위해 요구되는 범위가 누락)의 데이터에 액세스 할 권한이없는 경우에 슬로우.

하지만 권한이 문서는 말한다 때문에 기존의 비디오 소스를 업데이트하기위한 충분한 범위입니다 manage_videos 범위가 확신,

manage_videos : 사용자의 업로드 한 동영상을 수정하거나 삭제할 수 있습니다 새로운 것을 발표하는 것입니다. 동영상

상술, 만 title 필드 input_title 적절히 업데이트된다.

독서를 해주셔서 감사합니다. 조심스럽게 문서를 조사했지만 여전히이 답변을 이해하지 못합니다.

답변

0

파트너 사용자 만 비디오 원본 URL을 업데이트 할 수 있습니다.

최고,