Ontener Dailymotion video id with PHP API

1

I'm using the dailymotion API to upload videos but I want to get the id of the newly uploaded video but I do not know how to do it. Could someone help me?

I have this code:

$api->setGrantType(
                    Dailymotion::GRANT_TYPE_PASSWORD,
                    $apiKey,
                    $apiSecret,
                    array('write', 'delete', 'manage_videos'), // OAuth 2.0 scopes that you'd like to be granted by the end-user
                    array(
                        'username' => dailymotion_uname, // don't forget to sanitize this,
                        'password' => dailymotion_password, // never use POST variables this way
                    )
                );


             // $data['video_id'] = "test";

                $url = $api->uploadFile( getcwd().DIRECTORY_SEPARATOR ."video".DIRECTORY_SEPARATOR .$data['video_id'].".mp4");
                $api->post(
                    '/me/videos',
                    array(
                        'url'       => $url,
                        'title'     => $data['title'],
                        'description'      => $data['info'],
                        'channel'   => dailymotion_channel,
                        'published' => true,
                    )

                );

If someone wants to help me, I leave you the documentation of the api:

link

    
asked by Jose Rodriguez 02.06.2017 в 02:44
source

1 answer

2

The api of dailymotion is not very clear about it, but what you are doing is correct, you just need to read the answer.

$url = $api->uploadFile( getcwd().DIRECTORY_SEPARATOR ."video".DIRECTORY_SEPARATOR .$data['video_id'].".mp4");
$respuesta = $api->post(
                '/me/videos',
                array(
                    'url'       => $url,
                    'title'     => $data['title'],
                    'description'      => $data['info'],
                    'channel'   => dailymotion_channel,
                    'published' => true,
                )
            );
$video_id = $respuesta['id']

As the documentation tells you, uploadFile uploads the file and returns a url so you can publish it with the method - > post(). this api-> post is the one that returns the id of the video already published.

I'd tell you to do a print_r($respuesta) to see all the variables it returns, I'm not sure it returns in case of error, you sure have to catch DailymotionApiException , but if you want to make it simple you could ask if isset($respuesta['id']) .

I hope I help you.

    
answered by 02.06.2017 / 03:22
source