{"id":61,"date":"2013-12-01T17:44:35","date_gmt":"2013-12-01T18:04:39","guid":{"rendered":"https:\/\/620ddbitly_logo.png"},"modified":"2015-08-14T09:29:45","modified_gmt":"2015-08-14T15:29:45","slug":"clase-para-generar-enlaces-de-bitly-desde-php","status":"publish","type":"post","link":"https:\/\/emanuelpaxtian.com\/blog\/clase-para-generar-enlaces-de-bitly-desde-php\/","title":{"rendered":"Clase para generar enlaces de bitly desde php."},"content":{"rendered":"<p>Que es Bitly<\/p>\n<p>Esta herramienta se usa frecuentemente en la red de microblogging Twitter, como reductor de URLs un\u00a0servicio que ofrece es la posibilidad de generar estad\u00edsticas a partir de los clics sobre los v\u00ednculos.<\/p>\n<p>Primero crearemos la clase de php para generar el enlace acortado.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass BitLy\r\n{\r\n    private $user;\r\n    private $key;\r\n    private $urlTemp;\r\n    private $urlApi = &quot;http:\/\/api.bit.ly\/v3\/&quot;;\r\n    public function __construct($user, $key) {\r\n        $this-&amp;gt;user = $user;\r\n        $this-&amp;gt;key  = $key;\r\n    }\r\n    public function shortUrl($url) {\r\n        $this-&amp;gt;urlTemp = $this-&amp;gt;urlApi . &quot;shorten?login=&quot; . $this-&amp;gt;user . &quot;&amp;amp;apiKey=&quot; . $this-&amp;gt;key . &quot;&amp;amp;uri=&quot; . $url . &quot;&amp;amp;format=txt&quot;;\r\n        return file_get_contents($this-&amp;gt;urlTemp);\r\n    }\r\n    public function largeUrl($url) {\r\n        $this-&amp;gt;urlTemp = $this-&amp;gt;urlApi . &quot;expand?login=&quot; . $this-&amp;gt;user . &quot;&amp;amp;apiKey=&quot; . $this-&amp;gt;key . &quot;&amp;amp;shortUrl=&quot; . $url . &quot;&amp;amp;format=txt&quot;;\r\n        return file_get_contents($this-&amp;gt;urlTemp);\r\n    }\r\n}\r\n<\/pre>\n<p>Ahora aqui la manera de usar la clase para ello utilizaremos el <strong>usuario<\/strong> de bitly y el <strong>apikey<\/strong> proporcionado por el servicio.<\/p>\n<p><a href=\"https:\/\/bitly.com\/a\/your_api_key\">https:\/\/bitly.com\/a\/your_api_key<\/a><\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$bitly = new BitLy(usuariobit,api_key);\r\n$bitc= $bitly-&amp;gt;shortUrl(&quot;https:\/\/emanuelpaxtian.com\/blog&quot;);\r\necho $bitc;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Que es Bitly Esta herramienta se usa frecuentemente en la red de microblogging Twitter, como reductor de URLs un\u00a0servicio que ofrece es la posibilidad de generar estad\u00edsticas a partir de&hellip;<\/p>\n","protected":false},"author":1,"featured_media":499,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-61","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/posts\/61","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/comments?post=61"}],"version-history":[{"count":0,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/posts\/61\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/media\/499"}],"wp:attachment":[{"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/media?parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/categories?post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/emanuelpaxtian.com\/blog\/wp-json\/wp\/v2\/tags?post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}