GithubHelp home page GithubHelp logo

kels / dailymotion-sdk-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dailymotion/dailymotion-sdk-php

0.0 1.0 0.0 86 KB

Dailymotion PHP client API

Home Page: http://www.dailymotion.com/doc/api

dailymotion-sdk-php's Introduction

Dailymotion PHP SDK

This repository contains the official open source PHP SDK that allows you to access the Dailymotion API from your website.

Usage

Authentication

The Dailymotion API requires OAuth 2.0 authentication in order to be used. This library implements three granting methods of OAuth 2.0 for different kind of usages.

Authorization Grant Type

This mode is the mode you should use in most cases. In this mode you redirect the user to an authorization page on Dailymotion, and you script is called back once the end-user authorized your API key to access the Dailymotion service on its behalf.

Here is a usage example:

<?php

$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_AUTHORIZATION, $apiKey, $apiSecret)

try
{
    $result = $api->get('/me/videos', array('fields' => 'id,title,description'));
}
catch (DailymotionAuthRequiredException $e)
{
    // Redirect the user to the Dailymotion authorization page
    header('Location: ' . $api->getAuthorizationUrl());
    return;
}
catch (DailymotionAuthRefusedException $e)
{
    // Handle case when user refused to authorize
    // <YOUR CODE>
}

Password Grant Type

If you PHP application isn't a web application and cannot redirect the user to the Dailymotion authorization page, the password grant type can be used. With this grant type you have the responsibility to ask the user for its credentials. Make sure you API secret remains secret though.

<?php

$api = new Dailymotion();

if (isset($_POST['username']) || isset($_POST['password']))
{
    $api->setGrantType(Dailymotion::GRANT_TYPE_PASSWORD, $apiKey, $apiSecret, $scope = array('manage_videos'),
                       array('username' => $_POST['username'], 'password' => $_POST['password']));
}
else
{
    $api->setGrantType(Dailymotion::GRANT_TYPE_PASSWORD, $apiKey, $apiSecret, $scope = array('manage_videos'));
}

try
{
    $result = $api->get('/me/videos', array('fields' => 'id,title,description'));
}
catch (DailymotionAuthRequiredException $e)
{
    // Ask user's Dailymotion login/password
    // <YOUR CODE>
}

Client Credentials Grant Type

If you don't need to access the Dailymotion API on behalf of a user because, for instance, you plan to only access public data, you can use the CLIENT_CREDENTIALS grant type. With this grant type, you will only have access to public data or private date of the user owning the API key.

<?php

$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_CLIENT_CREDENTIALS, $apiKey, $apiSecret);
$result = $api->get('/videos', array('fields' => 'id,title,description'));

File Upload

Certain methods like POST /videos requires a URL to a file. To create those URLs, the uploadFile() method can be used to create such URL:

$url = $api->uploadFile($filePath);

You can then use this URL as an argument to methods requiring a URL parameter. For instance to create a video:

$result = $api->post('/videos', array('url' => $url));

Feedback

We are relying on the GitHub issues tracker linked from above for feedback. File bugs or other issues here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.