10

I am trying to use an authorization header in order to use the vimeo API.

It tells me to do this 'Authorization: basic ' + base64(client_id + ':' + client_secret) , which is something I can do.

But nowhere on the internet does it tell me what I actually do with this code? It is not PHP, but does it go in a PHP file? If so then what function do I use on it after storing it? Does it go in an htaccess file?

It is really sad how terrible any and all online documentation is on this.

To summarize, basically what I'm saying is SHOW ME THE CODE

Alexis Wilke
  • 19,179
  • 10
  • 84
  • 156
Sam Alexander
  • 504
  • 1
  • 6
  • 24

3 Answers3

23
$api_url = 'http://myapiurl';

$client_id = 'myclientid';
$client_secret = 'myclientsecret';

$context = stream_context_create(array(
    'http' => array(
        'header' => "Authorization: Basic " . base64_encode("$client_id:$client_secret"),
    ),
));

$result = file_get_contents($api_url, false, $context);

Documentation links:

For more complex requests, you can use cURL, but the library's PHP implementation is a mess and I prefer to avoid it when I can. Guzzle is a library that abstracts a lot of the complexities here.

Mikkel
  • 1,192
  • 9
  • 22
  • base64_encode is what I was looking for, for one API docs they have written that I need to use `md5("$client_id:$client_secret")`, but it doesn't work and I tried base64_encode and it works. :D – Oleg Abrazhaev Mar 27 '18 at 12:56
2

Vimeo highly recommends you do not write these authentication systems yourself, but use the official libraries: https://github.com/vimeo/vimeo.php.

If you are looking for a custom PHP integration, it varies based on the way you make HTTP requests. guzzle and curl are both http request libraries, with their own ways of setting headers (http://guzzle.readthedocs.org/en/latest/request-options.html#headers and PHP cURL custom headers)

As for base64 encoding your tokens, use the method base64_encode (http://php.net/manual/en/function.base64-encode.php)

Community
  • 1
  • 1
Dashron
  • 3,968
  • 2
  • 14
  • 21
-3

$curl = base64_encode("1100032342:F!rSTU99HD"); echo $curl;

RESULT:
MTEwMDAzMjM0MjpGIXJTVFU5OUhE

Rajon Kobir
  • 173
  • 2
  • 4