bitly php url 不起作用?
在职的!!!
$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);
在职的!!!
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);
不工作! 知道为什么吗?如果我打印出 $shareurl,我可以看到这是一个完全正常的 url,我可以将其粘贴到正常的 bit.ly 网站上。
我不明白!有什么想法吗?如果你能帮助我那就太好了!
我还有一个问题。我不是一个 php 专家,但我想如果我打电话给 bitly 服务与此行 $bitly->shorten($shareurl); 几次它的性能不是很好。
$bitly = new bitly('myusername', 'myapikey');
print $bitly->shorten($shareurl);
我不能将这个小小的请求保存到 var 并将其粘贴到我需要的地方吗? 例如,我有一些共享链接,我总是使用这个位链接。
$output .= "… share this link <a href=" . 'mailto:?subject=hello&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>";
有更好的方法吗?而不是执行三次 bitly 请求?
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('myusername', '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 .= "… share this link <a href=" . 'mailto:?subject=hello&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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你需要对你的哈希字符进行urlencode。尝试
I think you need to urlencode your hash character. Try
您需要在域名尾部添加斜杠。
$shareurl = $currenturl 。 '/#' 。 $url;
You need a trailing slash on the domain name.
$shareurl = $currenturl . '/#' . $url;