save to codehub
This commit is contained in:
24
resources/views/Admin/function.php
Normal file
24
resources/views/Admin/function.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?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'];
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user