user3659818
user3659818

Reputation:

How to replace an existing video in Dailymotion API?

I'm building an app using Dailymotion API https://developer.dailymotion.com/ with official python sdk https://github.com/dailymotion/dailymotion-sdk-python and writing video CRUD(Create, Read, Update, Delete) simply. Create, Read, Delete were succeccfully completed, but encountering a weird response of the API about "Update".

Here is a simplified snippet of my code in my Django project,

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

but the update fails except title field with the following message, 'access_forbidden: You are not allowed to change existing video source.'

from doc,

access_forbidden: Thrown when the user doesn't have the permission to access the data (e.g. missing a required scope to access certain fields).

but I'm sure that the permission has manage_videos scope which is an enough scope to update the existing video source because the doc says,

manage_videos: Allows to modify or delete the user's uploaded videos and to publish new ones.

and described above, Only the title field of the video is updated with the input_title properly.

Thanks for reading, I researched their docs carefully, but still don't understand this response.

Upvotes: 0

Views: 641

Answers (1)

dailymotion
dailymotion

Reputation: 1596

Only partner users can update the video source urls.

Best,

Upvotes: 0

Related Questions