bitly php url 不起作用?

发布于 2024-08-24 10:03:58 字数 1597 浏览 7 评论 0原文

shorten('http://www.google.com'); ?>

在职的!!!

$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 .= "&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>";

有更好的方法吗?而不是执行三次 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦初醒的夏天 2024-08-31 10:03:58

我认为你需要对你的哈希字符进行urlencode。尝试

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

I think you need to urlencode your hash character. Try

$shareurl = $currenturl . urlencode('#') . $url;
橪书 2024-08-31 10:03:58

您需要在域名尾部添加斜杠。 $shareurl = $currenturl 。 '/#' 。 $url;

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文