Dailymotion API : “Invalid authorization code”-Collection of common programming errors
The question is obviously referring to the reference code provided by Dailymotion at https://github.com/dailymotion/dailymotion-sdk-php , which gives the exact error described by Hammou Moncef if you try using it to upload a video.
Dailymotion doesn’t provide a test script that you can use with OAuth, just a unit-testing thing that uses the username/password authentification. I used the following code and the OP must have used something similar.
require_once dirname(__FILE__) . '/Dailymotion.php';
$testVideoFile = '/path/to/file';
$apiKey = 'MY_API_KEY';
$apiSecret = 'MY_API_SECRET';
$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, $apiKey, $apiSecret, array('manage_videos'));
$url = $api->uploadFile($testVideoFile);
$result = $api->call('video.create', array('url' => $url));
This is after authorizing my app to upload videos to the user account, with a standard OAuth 2 flow that appears to return a valid code parameter. Except when you try to redeem it for an access token, Dailymotion gives you the previously mentioned error message.
I applied JLepage’s fix, it changes nothing.
There’s even a 2-year-old open issue on their Github about this, wow: https://github.com/dailymotion/dailymotion-sdk-php/issues/2