-1

I'm trying to use the Dailymotion API. I followed every instruction possible but I keep getting errors, although I'm using the changes that people have suggested in other posts ie. DailyMotion Invalid authorization code

The errors I'm getting

Fatal error: Uncaught DailymotionAuthRequiredException in /Library/WebServer/Documents/basic/Dailymotion.php:582 Stack trace:

0 /Library/WebServer/Documents/basic/Dailymotion.php(404): Dailymotion->getAccessToken()

1 /Library/WebServer/Documents/basic/Dailymotion.php(356): Dailymotion->call('GET /file/uploa...', Array)

2 /Library/WebServer/Documents/basic/Dailymotion.php(326): Dailymotion->get('/file/upload', Array)

3 /Library/WebServer/Documents/basic/index.php(12): Dailymotion->uploadFile(NULL)

4 {main} thrown in /Library/WebServer/Documents/basic/Dailymotion.php on line 582

Am I missing something in my php? I've not seen anyone reference the getAccessToken.

<?
include("Dailymotion.php");

$apiKey = "xxxxxxxxxxxxxxx";
$apiSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
$user = "my username";
$pwd = "my password";
$filepath = "Test.mp4";

$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_PASSWORD, $apiKey, $apiSecret, array('manage_videos', 'write','delete'), array('username' => $user, 'password' => $pwd));
$url = $api->uploadFile($filepath);
$result = $api->call('video.create', array(
    'url' => $url,
    'title' => $title,
    'description' => $description,
    'private' => 'false',
    'published' => 'true',
));
?> 
  • `$filepath` !== `$filePath` – Alon Eitan May 30 '20 at 10:59
  • Cheers for pointing out the $filepath. I spotted another error, so went back to the SDK https://developer.dailymotion.com/video-upload/how-to-upload-videos-api-php-sdk/ But after fixing my code I'm now getting an additional error #0 /Library/WebServer/Documents/basic/Dailymotion.php(590): Dailymotion->oauthTokenRequest(Array) I know what you mean about undefined variables, but I can't find anything in the examples I'm find or in the link about that references about Token placing. – Scott McGee May 30 '20 at 13:12

1 Answers1

0

figured out the answer, I kept assuming peoples answers where just as is. I didn't realise I had to put it into another bit to authorise my account.


require_once 'Dailymotion.php';
// Account settings
$apiKey        = 'your apikey';
$apiSecret     = 'your secret';
$testUser      = 'your username';
$testPassword  = 'your password';

// Scopes you need to run your tests
$scopes = array(
    'manage_videos',
);
// Dailymotion object instanciation
$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, $apiKey, $apiSecret);

try
{
    // The following line will actually try to authenticate before making the API call.
    // * The SDK takes care of retrying if the access token has expired.
    // * The SDK takes care of storing the access token itself using its `readSession()`
    //   and `storeSession()` methods that are made to be overridden in an extension
    //   of the class if you want a different storage than provided by default.
    $url = $api->uploadFile('Test.mp4');
    $result = $api->call('video.create', array(
    'url' => $url,
    'title' => 'prove this works',
    'description' => 'THis is purely a test',
    'private' => 'false',
    'published' => 'true'
));
    var_dump($result);
}
catch (DailymotionAuthRequiredException $e)
{
    // If the SDK doesn't have any access token stored in memory, it tries to
    // redirect the user to the Dailymotion authorization page for authentication.
    return header('Location: ' . $api->getAuthorizationUrl());
}
catch (DailymotionAuthRefusedException $e)
{

}

?>