Pergunta

I'd like to use the method vimeo.videos.getInfo to get the info on a private video uploaded to my account. I'll only ever use this application on one website, so I'm hard coding the access token into the code.

I'm using the official PHP library for the Vimeo API (https://github.com/vimeo/vimeo.php).

So here's what I have so far...

$vimeo = new Vimeo($apiKey, $apiSecret, $accessToken);

All good. At first, when I tried the sample code from the example:

$user_data = $vimeo->request('/me');
print_r($user_data);

That returned an empty array:

Array (
    [body] => 
    [status] => 0
    [headers] => Array
        (
        )

)

I noticed they mentioned if the array is returning empty, it probably had something to do with an invalid SSL certificate. Right now, I'm just developing on localhost, so I set CURLOPT_SSL_VERIFYPEER to false (thanks to these instructions: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/). I added it to the array on line 112 in vimeo.php:

$curl_opt_defaults = array(
CURLOPT_HEADER => 1,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false);

As soon as I did that, I was able to return the information about the authenticated user.

But this still is returning an empty array:

$params = array(
    'video_id' => 95307197
);
$videos = $vimeo->request('vimeo.videos.getInfo', $params);
print_r($videos);

Same with any methods I try to put in there. Did I do the CURLOPT_SSL_VERIFYPEER thing wrong or is something else wrong with my syntax?

Foi útil?

Solução 3

Hopefully this helps someone else. The Vimeo API documentation is all out of whack and the new API docs link back to the older API docs, which only adds to the confusion.

The new API doesn't use the methods from the Advanced API, it uses the endpoints here https://developer.vimeo.com/api/endpoints

Here is the code that eventually worked for me:

$videos = $vimeo->request("/videos/$video_id");
print_r($videos);

Outras dicas

I thought that I might share my solution which took me some time to figure out. I also wanted to access private video data, namely the number pf time the video played. Here are my steps:

  1. Create an app on Vimeo and get the Client Identifier, Client Secret, and generate an Access Token with the properties Public, Private, and Interact. You may need to add or remove properties based on your access need.
  2. Download from Vimeo the PHP source code.
  3. Strangely, at least in my case, the code had a wrong syntax on line 473 in the statement $name = array_slice(explode("/", $file_path), -1)[0]; to solve it remove the [0] at the end! In fact I didn't need to call this function to know if it did any harm, but this solved my problem. Am on Dreamweaver by the way.
  4. More strangely, the PHP code provided my Vimeo can not do authentication with their new system so you need to add this code curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); before every $response = curl_exec($curl); statement. This should be 3 additions.
  5. Finally, create your own PHP script to access the private video.

Here is my Code:

require("../Vimeo PHP path/autoload.php");
use Vimeo\Vimeo;
$client_id = "*****"; //your Vimeo number here
$client_secret = "*****"; //your Vimeo number here
$access_token = "*****"; //your Vimeo number here

$vim = new Vimeo($client_id, $client_secret, $access_token);
$response = $vim->request("/videos/****"); //your Vimeo PRIVATE video ID here
echo $response["body"]["stats"]["plays"];

In my case I did echo for the number of plays only, but you can print the whole body. Hope this helps someone too.

Thanks to this example I solved the same issue, in the current api at _request method(line 125) add the curl option CURLOPT_SSL_VERIFYPEER and set it to false so you will have an array like this:

$curl_opt_defaults=array(CURLOPT_HEADER => 1, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_SSL_VERIFYPEER=>false);

and that's all :) hope this helps someone else.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top