GithubHelp home page GithubHelp logo

eliuflorez / vimeo.php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vimeo/vimeo.php

0.0 2.0 0.0 616 KB

Official PHP library for the Vimeo API.

Home Page: https://developer.vimeo.com/api

License: Apache License 2.0

PHP 100.00%

vimeo.php's Introduction

Index

Get started with the Vimeo API

There is a lot of information about the Vimeo API at https://developer.vimeo.com/api/start. Most of your questions will be answered there!

Direct Help

NOTE: How to use the PHP library with the Vimeo Docs.

The API docs often uses dot notation to represent a hierarchy of data (eg. privacy.view). Because this library sends all data using JSON, you must use nested associative arrays, not dot notation.

// The docs refer to the following as "privacy.view"
array('privacy' => array('view' => 'disable'));

Installation

Composer

  1. Add the vimeo library to your composer.json file's require field
{
	"require" : {
		"vimeo/vimeo-api" : "1.1.*"
	}
}
  1. Use the library $lib = new \Vimeo\Vimeo($client_id, $client_secret)

Manual

  1. Download the latest release : v1.1.0
  2. Include the autoloader require("/path/to/vimeo.php/autoload.php");
  3. Use the library $lib = new \Vimeo\Vimeo($client_id, $client_secret)

Generate your Access token

All requests require access tokens. There are two types of access tokens.

  • Unauthenticated - Access tokens without a user. These tokens can only view public data
  • Authenticated - Access tokens with a user. These tokens interact on behalf of the authenticated user.

Unauthenticated

Unauthenticated API requests must generate an access token. You should not generate a new access token for each request, you should request an access token once and use it forever.

// scope is an array of permissions your token needs to access. You can read more at https://developer.vimeo.com/api/authentication#scopes
$token = $lib->clientCredentials(scope);

// usable access token
var_dump($token->access_token);

// accepted scopes
var_dump($token->scope);

// use the token
$lib->setToken($token->access_token)

Authenticated

  1. Build a link to Vimeo so your users can authorize your app.
$url = $lib->buildAuthorizationEndpoint($redirect_uri, $scopes, $state)
Name Type Description
redirect_uri string The uri the user is redirected to in step 3. This value must be provided to every step of the authorization process including creating your app, building your authorization endpoint and exchanging your authorization code for an access token.
scope array An array of permissions your token needs to access. You can read more at https://developer.vimeo.com/api/authentication#scopes.
state string A value unique to this authorization request. You should generate it randomly, and validate it in step 3.
  1. Your user will need to access the authorization endpoint (either by clicking the link or through a redirect). On the authorization endpoint the user will have the option to deny your app any scopes you have requested. If they deny your app, they will be redirected back to your redirect_url with an error parameter.

  2. If the user accepts your app, they will be redirected back to your redirect_uri with a code and state query parameter (eg. http://yourredirect.com?code=abc&state=xyz).

    1. You must validate that the state matches your state from step 1.
    2. If the state is valid, you can exchange your code and redirect_uri for an access token.
// redirect_uri must be provided, and must match your configured uri
$token = $lib->accessToken(code, redirect_uri);

// usable access token
var_dump($token->access_token);

// accepted scopes
var_dump($token->scope);

// authenticated user
var_dump($token->user);

// use the token
$lib->setToken($token->access_token)

For additional information, check out the example

Make requests

The API library has a request method which takes three parameters. It returns an associative array containing all of the relvant request information.

Usage

Name Type Description
url string The URL path (e.g.: /users/dashron).
params string An object containing all of your parameters (e.g.: { "per_page": 5, "filter" : "featured"} ).
method string The HTTP method (e.g.: GET).
$response = $lib->request('/me/videos', array('per_page' => 2), 'GET');

Response

The response array will contain three keys.

Name Type Description
body assoc array The parsed request body. All responses are JSON so we parse this for you, and give you the result.
status number The HTTP status code of the response. This partially informs you about the success of your API request.
headers assoc array An associative array containing all of the response headers.
$response = $lib->request('/me/videos', array('per_page' => 2), 'GET');
var_dump($response['body']);

Upload videos from the Server

To upload videos you must call the upload method. It accepts two parameters. It will return the URI of the new video. For more information check out the example

Name Type Description
file string Full path to the upload file on the local system.
upgrade boolean (Optional) Defaults to false. Requests for a 1080p encode to be made from this video. This feature is only available to Vimeo PRO members. For more information, check out the FAQ.
$response = $lib->upload('/home/aaron/Downloads/ada.mp4', false)

Replace videos from the Server

To replace the source file of a video, you must call the replace method. It accepts three parameters. It will return the URI of the replaced video.

Name Type Description
video_uri string The URI of the original video. Once uploaded and successfully transcoded your source video file will be swapped with this new video file.
file string Full path to the upload file on the local system.
upgrade boolean (Optional) Defaults to false. Requests for a 1080p encode to be made from this video. This feature is only available to Vimeo PRO members. For more information, check out the FAQ.
$response = $lib->upload('/videos/12345', '/home/aaron/Downloads/ada.mp4', false)

Upload or replace videos from the client

To upload from the client, you will have to mix some server side, and client side API requests. We support two workflows, the first of which is much easier than the second.

Simple POST uploads

This workflow is well documented on Vimeo's developer site. You can read more here : https://developer.vimeo.com/api/upload#http-post-uploading.

Streaming uploads

Streaming uploads support progress bars, and resumable uploading. If you want to perform these uploads client side you will need to start with some server side requests. Read through the Vimeo documentation first. Step 1 and 4 should be performed on the server, while step 2 and 3 can be performed on the client. With this workflow the video will never be transferred to your servers.

Upload images

To upload an image, call the uploadImage method. It takes three parameters. For more information check out the example

Name Type Description
pictures_uri string The URI to the pictures collection for a single resource. eg. /videos/12345/pictures. You can always find this in the resource representation.
file string Full path to the upload file on the local system.
activate boolean (Optional) Defaults to false. If true this picture will become the default picture for the associated resource.
$response = $lib->uploadImage('/videos/12345/pictures', '/home/aaron/Downloads/ada.png', true)

Troubleshooting

If your API request returns with an empty array, or a status code of 0 it likely means you do not have the proper https certificates. You can read more here : http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/. Note that we highly recommend the full solution. The quick fix will leave your tokens vulnerable.

If you have any additional questions or problems, create a ticket or contact us

Framework Integrations

If you have integrated Vimeo into a popular PHP framework let us know!

Contributors

vimeo.php's People

Contributors

dashron avatar dstelljes avatar greedo avatar karlhorky avatar videomonkey avatar vinkla avatar

Watchers

 avatar  avatar

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.