3

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);
?>
Rupesh Yadav
  • 12,096
  • 4
  • 53
  • 70
dg85
  • 490
  • 2
  • 7
  • 21

1 Answers1

2

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");
Maxime Pacary
  • 22,336
  • 11
  • 85
  • 113
  • Thanks, i tried to vote up but apparently i require 15 rep. Works great now. Marked as correct, thanks for your help. – dg85 Mar 13 '11 at 15:51