2016-10-03 3 views
0

私は公式のPython SDK https://github.com/dailymotion/dailymotion-sdk-python と書き込みビデオCRUD(作成、読み取り、更新、削除)するだけでDailymotionのAPIを https://developer.dailymotion.com/ を使用してアプリケーションを構築しています。 作成、読み取り、削除は成功裏に完了しましたが、APIの「更新」に関する奇妙な応答に遭遇しました。ここでDailymotion APIの既存のビデオを置き換えるにはどうすればいいですか?

は、私のDjangoのプロジェクトで私のコードの簡略化スニペットです

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 

が、更新はaccess_forbidden次のメッセージ、 」でtitleフィールドを除いて失敗します。あなたは、既存のビデオソースを変更することはできません。 DOCから

access_forbidden:ユーザーがデータにアクセスする権限を持っていない場合にスローされ(例えば、特定のフィールドにアクセスするために必要な範囲を欠落)。

が、私は許可がドキュメントが言うので、既存のビデオソースを更新するのに十分な範囲であるスコープ、

manage_videosを持っていることを確信している:ユーザーのアップロードした動画を修正または削除することができます新しいものを公表すること。ビデオの

と上記、 のみtitleフィールドが正しくinput_titleで更新されます。

読んでいただきありがとうございます。私は慎重にドキュメントを調査しましたが、まだこの回答を理解していません。

答えて

0

ビデオソースURLを更新できるのはパートナーユーザーだけです。

ベスト、

関連する問題