So I'm trying to retrieve an access_token from to use their url shorten API call. Everytime I make the curl call I get INVALID_CLIENT_ID as a response. I quadruple checked, all my keys are fine. What could be happening?

Here is the code:


function curl($url, $params) {

    $params_str = http_build_query($params);
    $curl = curl_init();
    $header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
    $header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
    $header[] = "Cache-Control: max-age=0";
    $header[] = "Connection: keep-alive";
    $header[] = "Keep-Alive: 300";
    $header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[] = "Accept-Language: en-us,en;q=0.5";
    $header[] = "Pragma: "; // browsers keep this blank.

    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
    curl_setopt($curl, CURLOPT_POST,count($params));
    curl_setopt($curl, CURLOPT_POSTFIELDS,urlencode($params_str));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $rs = curl_exec($curl);
    return $rs;

$access_token = curl('',array('client_id'=>BITLY_CLIENT_ID,'client_secret'=>BITLY_CLIENT_SECRET,'x_auth_username'=>'MY_USERNAME','x_auth_password'=>'MY_PASSWORD'));

echo $access_token;exit; // Returns INVALID_CLIENT_ID


From API documentation: Authentication via XAuth must be requested by e-mailing

Could this be the reason?

Also, urlencoding the whole $params_str looks suspicious.

So I emailed earlier today (Awesome service btw, quick and polite), this is the response they gave to me:

If all you're looking to do is to get an access_token for your own account, I suggest using the basic auth mechanism documented at Just load up terminal and curl the following URL w/ your username and password:

curl -u "username:password" -X POST ""

So run this and copy and paste your access_token into your config.

My new curl call looked like this:


P.S - urlencoding the $params_str broke the call too. Thanks timoh!

Need Your Help

Escaping curl command in Windows

windows curl marklogic

I'm trying to run a curl command from the command line in Windows, but for the life of me I can't figure out how I'm supposed to escape it.