I get INVALID_URI eventhough it's a valid url

763 views
Skip to first unread message

Yehuda Tzadik

unread,
Jun 6, 2016, 9:00:04 AM6/6/16
to Bitly API
That's the output
string(84) "{"errorCode": 500, "errorMessage": "INVALID_URI", "results": null, "statusCode": ""}"
array(4) {
  ["errorCode"]=>
  int(500)
  ["errorMessage"]=>
  string(11) "INVALID_URI"
  ["results"]=>
  NULL
  ["statusCode"]=>
  string(0) ""
}

In v2 I got other error message


Here is the code

<?php

$ch = curl_init();

$token = 'a1ab30ed221a';


$a_link_params = array (
'uri'     =>  urlencode('http://10comm.com/Pinukim.php'),
'longUrl' =>  urlencode('http://10comm.com/Pinukim.php'),
'login'   =>  'mylogin',
'apiKey'  =>  'myapikey',
'format'  =>  'json'
);

$url .= '?' . http_build_query($a_link_params);
echo "url: " . $url . "<br>";

$a_curl_options = array (
        CURLOPT_URL             =>  $url,
        CURLOPT_RETURNTRANSFER  =>  1,
        CURLOPT_CONNECTTIMEOUT  =>  30
);
curl_setopt_array($ch, $a_curl_options);

curl_setopt($ch, CURLOPT_POST, false);

$result = curl_exec($ch);  
echo "<pre>";var_dump($result);echo "</pre>";

curl_close($ch);

$obj = json_decode($result, true);
echo "<pre>";var_dump($obj);echo "</pre>";  

// $SLink =  $obj["results"]["longurl"]["shortUrl"];  
 
//echo $SLink; ?>

Sean O'Connor

unread,
Jun 6, 2016, 9:49:36 AM6/6/16
to bitly API
Hello Yehuda,

There are two issues I'm seeing that are probably leading to your problem:

1.  You are providing both uri and longUrl parameters.  You should only provide a longUrl parameter.
2.  In the code sample you provided, longUrl gets double encoded.  http_build_query encodes the parameters provided so the earlier urlencode leads to the parameters getting double encoded which would result in an invalid URL.

If you resolve these issues, your provided code should work.

Hope this helps, let us know if you have any further questions.

Sean O'Connor
Director of Application Engineering, Bitly
Twitter | Facebook | Github
@theSeanOC



--
You are subscribed to the Bitly API discussion group.
for API Documentation visit http://dev.bitly.com/
---
You received this message because you are subscribed to the Google Groups "Bitly API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bitly-api+...@googlegroups.com.
To post to this group, send email to bitl...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages