Enviado em 21/04/2016 - 09:59h
Oi galera! Criei um código aqui! Que utiliza o URL Shortener API do Google! Mas do nada ele dá erros!
[21-Apr-2016 12:47:40 UTC] PHP Notice: Undefined variable: shortUrl in /home/kogupvpc/public_html/apis/url-short/index.php on line 125
[21-Apr-2016 12:47:40 UTC] PHP Notice: Undefined variable: shortUrl in /home/kogupvpc/public_html/apis/url-short/index.php on line 125
[21-Apr-2016 12:47:40 UTC] PHP Notice: Undefined index: short in /home/kogupvpc/public_html/apis/url-short/index.php on line 138
[21-Apr-2016 12:47:40 UTC] PHP Notice: Undefined property: stdClass::$id in /home/kogupvpc/public_html/apis/url-short/index.php on line 160
[21-Apr-2016 12:47:48 UTC] PHP Notice: Undefined variable: shortUrl in /home/kogupvpc/public_html/apis/url-short/index.php on line 125
[21-Apr-2016 12:47:48 UTC] PHP Notice: Undefined variable: shortUrl in /home/kogupvpc/public_html/apis/url-short/index.php on line 125
<!DOCTYPE html>
<html lang="pt">
<head>
<title>VicioGamesBR -=- APIs - Prntscr.com Direct</title>
<meta charset="ansi">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<style>
h3 {
color: #47B1FF;
}
.navbar-inverse {
background-color: transparent;
border-color: transparent;
}
body {
background-image: url("/img/bg.png");
color: #000000;
}
.navbar {
margin-bottom: 0;
border-radius: 0;
}
footer {
background-color: #28B2FF;
padding: 25px;
}
.carousel-inner img {
width: 100%;
margin: auto;
min-height:200px;
}
@media (max-width: 600px) {
.carousel-caption {
display: none;
}
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<b>
<a class="navbar-brand" href="/">VicioGamesBR</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a href="/"><i class="fa fa-home"></i> Início</a></li>
<li><a href="/sobre"><i class="fa fa-question"></i> Sobre</a></li>
<li><a href="http://viciogamesbr.com/forum"><i class="fa fa-group"></i> Fórum</a></li>
<li class="active"><a href="/apis"><i class="fa fa-gears"></i> APIs</a></li>
<li><a href="/doar"><i class="fa fa-gift"></i> Doar</a></li>
<li><a href="/contacto"><i class="fa fa-phone"></i> Contacto</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><i class="fa fa-shopping-basket"></i> Serviços
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Sites</a></li>
<li><a href="/downloads">Plugins / Skripts</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
</b>
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="/img/img1.png" alt="Image">
<div class="carousel-caption">
<h3></h3>
<p></p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
<span class="sr-only">Antes</span>
</a>
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
<span class="sr-only">Próximo</span>
</a>
</div>
<b>.</b>
<div class="container text-center">
<div class="well">
<h2>Encurtador de URL!</h2>
<img src="/img/info2.png">
<h3>Tem alguma URL longa? Encurte-a aqui! Basta colar o link na área indicada! E você terá um link pequeno!</h3>
<h2>Insira o link aqui:</h2>
<div class="form-group">
<form name="api" method="post" action="index.php">
<input type="text" class="form-control" id="short" name="short">
<input type="submit" class="btn btn-warning" value="Encurtar!">
</form>
<a href="<?php echo ($shortUrl); ?>"><button class="btn btn-info"><?php echo ($shortUrl); ?></button></a>
</div>
</div>
</div></b>
<footer class="container-fluid text-center">
<p><b>Site Desenvolvido pela © <a href="http://viciogamesbr.com">VicioGamesBR</a></b></p>
</footer>
<?php
$longUrl = $_POST['short'];
$apiKey = 'AIzaSyAV2FjUV132w6tV09PkElL5Ne-3oD_GFDI';
$postData = array('longUrl' => $longUrl, 'key' => $apiKey);
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url?key='.$apiKey);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($curlObj);
// Change the response json string to object
$json = json_decode($response);
$shortUrl = ($json->id);
curl_close($curlObj);
?>
</body>
</html>
Desktop Linux ganha fôlego enquanto distros refinam experiência e segurança
Wayland em alta, IA em debate e novos ventos para distros e devices
Qt 6.10 e Python 3.14 puxam o ritmo do software livre nesta quarta
Atualizações de Apps, Desktop e Kernel agitam o ecossistema Linux nesta terça-feira
Como mudar o nome de dispositivos Bluetooth via linha de comando
Adicionando o repositório backports no Debian 13 Trixie
Erro ao fazer remaster usando Penguin eggs (2)
Primeiras impressões do Debian 13 (25)
Meu Amigo não consegue entrar em meu mundo, via tailscale, hamachi e z... (1)