简体   繁体   中英

bit.ly php api - chopping off querystring parameter after '&' symbol?

I've got a Flash app that includes a twitter share for a customized mini application.

I'm achieving this very simply using flashvars passed in via a php querystring so your custom colour and message are passed to the mini-app.

The problem of course is url length for twitter so i'm looking to use the bit.ly api for php to shorten the dynamic url and pass that hashed url back to flash.

I've written a function to do this which works fine however it is chopping off the second querystring parameter after the first '&' symbol?

So for example, the following function running the url 'http://s46264.gridserver.com/apps/soundgirl/fbwall.php?colour=red&message=twittertest'

Gets shortened to http://bit.ly/i4kfj0 which, when parsed becomes http://s46264.gridserver.com/apps/soundgirl/fbwall.php?colour=red

It's chopping off the second querystring parameter. Anyone know of a way I can stop this from happening?

Thanks.

<?php

function bitly_shorten($url)
{
$username = "modernenglish";
$apikey = "myapikey";
$response = file_get_contents("http://api.bit.ly/v3/shorten?login=$username&apiKey=$apikey&longUrl=$url&format=json");
$response = json_decode($response);
if ($response->status_code == 200 && $response->status_txt == "OK")
{
return $response->data->url;
} else
{
return null;
}
}
$link = urldecode("http://s46264.gridserver.com/apps/soundgirl/fbwall.php?colour=red&message=twittertest");
echo bitly_shorten($link);
?>

Maybe try:

No urldecode() before calling bitly_shorten() :

$link = "http://s46264.gridserver.com/apps/soundgirl/fbwall.php?colour=red&message=twittertest";

Add urlencode() on the URL into your bitly_shorten() function:

$response = file_get_contents("http://api.bit.ly/v3/shorten?login=$username&apiKey=$apikey&longUrl=".urlencode($url)."&format=json");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM