开发者

bitly php url wont work?

开发者 https://www.devze.com 2022-12-22 12:38 出处:网络
shorten(\'http://www.google.com\'); ?> WORKING!!! $currenturl = (!empty($_SERVER[\'HTTPS\'])) ? \"https://\".$_SERVER[\'SERVER_NAME\'].$_SERVER[\'REQUEST_URI\'] : \"http://\".$_SERVER[\'SERVER_NAME
shorten('http://www.google.com'); ?>

WORKING!!!

$currenturl = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
include('bitly.php'); 
$bitly = new bitly('myusername', 'myapikey'); 
print $bitly->shorten($currenturl);

WORKING!!!

include('bitly.php'); 
$currenturl = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$url = "somehashtag"
$shareurl = $currenturl . '#' . $url;

$bitly = new bitly('myusername', 'myapikey'); 
print $bitly->shorten($shareurl);

NOT WORKING!!! Any idea why? If i print out the $shareurl i can see that it's a completely normal url that i could paste onto the normal bit.ly website.

I don't get it! Any ideas? Would be great if you could help me!


I've got one more question. I'm not much of an php expert, but I guess if I'm calling the bitly service with this line $bitly->shorten($shareurl); a few times it's not very performative.

$bitly = new bitly('m开发者_JS百科yusername', 'myapikey'); 
print $bitly->shorten($shareurl);

Can't i just save this bitly request to a var and paste it where i need it. For instance I'm having a few sharing links where i'm always using this bitly link.

$output .= "&hellip; share this link <a href=" . 'mailto:?subject=hello&amp;body=' . $bitly->shorten($shareurl) . ">via email?</a> <a href=" . 'http://www.facebook.com/sharer.php?u='. $bitly->shorten($shareurl) . '?t=hello' .">on facebook?</a> <a href=" . 'http://twitter.com/home?status=' . $bitly->shorten($shareurl) . ">on twitter?</a>";

Is there a better way to this? Instead of doing the bitly request three times?


I think you need to urlencode your hash character. Try

$shareurl = $currenturl . urlencode('#') . $url;


You need a trailing slash on the domain name. $shareurl = $currenturl . '/#' . $url;

0

精彩评论

暂无评论...
验证码 换一张
取 消