25 lines
756 B
PHP
25 lines
756 B
PHP
|
|
<?php
|
||
|
|
function shortenVideoUrl($longUrl) {
|
||
|
|
$accessToken = 'YOUR_ACCESS_TOKEN'; // replace with your Bitly access token
|
||
|
|
$url = 'https://api-ssl.bitly.com/v4/shorten';
|
||
|
|
$data = array(
|
||
|
|
'long_url' => $longUrl,
|
||
|
|
);
|
||
|
|
$headers = array(
|
||
|
|
'Authorization: Bearer ' . $accessToken,
|
||
|
|
'Content-Type: application/json',
|
||
|
|
);
|
||
|
|
$ch = curl_init();
|
||
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
||
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||
|
|
$result = curl_exec($ch);
|
||
|
|
curl_close($ch);
|
||
|
|
$response = json_decode($result, true);
|
||
|
|
return $response['link'];
|
||
|
|
}
|
||
|
|
|
||
|
|
?>
|