PHP Help

26 views
Skip to first unread message

Dwen Dooley

unread,
Oct 19, 2010, 6:49:10 PM10/19/10
to bitly API
Hello! Based on previous posts here and some web research I have been
trying to get a "lookup number of clicks" function to work in PHP (A
language I do not yet really "speak").

Any debugging help would be appreciated.

Thanks!

DwenD...@gmail.com

<?php


function get_bitly_clicks($shorturl) {
$bitly1 = "http://api.bit.ly/v3/clicks?shortUrl=";
$bitly1b = urlencode($shorturl);
$bitly2 = "&login=mybitlyname&apiKey=mybitlykey";

$bitly3 = "&format=json";

$url = $bitly1.$bitly1b.$bitly2.$bitly3;echo($shorturl);

//using curl
$curlObject = curl_init($url);
//curl_setopt($curlObject,CURLOPT_URL,$url);
curl_setopt($curlObject,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curlObject,CURLOPT_HEADER,false);

$result_json = curl_exec($curlObject);
curl_close($curlObject);

echo($result_json);

//decode JSON. Assumes that it is PHP5
$result = json_decode($result_json);

//return $result->results['user_clicks']; // This is where
I'm lost on the syntax the rest

return $result->{'data'}->{'clicks'}->{'user_clicks'}; //
seems to work just fine.

//return $result['data'][clicks][user_clicks];
}

$gotit = get_bitly_clicks('http://bit.ly/shorturl_to_check');

echo($gotit);

?>

Scott Herbert

unread,
Oct 20, 2010, 9:08:17 AM10/20/10
to bitl...@googlegroups.com
What do you get out the otherside when you run this?


--
You are subscribed to the bit.ly API discussion group.
To post, email to bitl...@googlegroups.com
For more options, visit http://groups.google.com/group/bitly-api



--
--
Scott Herbert
Web:  http://www.Scott-Herbert.com

Neil

unread,
Oct 20, 2010, 10:19:42 AM10/20/10
to bitl...@googlegroups.com
Your return line should read:

return $result->data->clicks[0]->user_clicks;

-- Neil

On Tue, Oct 19, 2010 at 11:49 PM, Dwen Dooley <dwend...@gmail.com> wrote:

Dwen Dooley

unread,
Oct 21, 2010, 1:02:42 AM10/21/10
to bitly API
Thank you! Works perfectly!

"Dwen"

On Oct 20, 10:19 am, Neil <nei...@gmail.com> wrote:
> Your return line should read:
>
> return $result->data->clicks[0]->user_clicks;
>
> -- Neil
>
>
>
> On Tue, Oct 19, 2010 at 11:49 PM, Dwen Dooley <dwendoo...@gmail.com> wrote:
> > Hello! Based on previous posts here and some web research I have been
> > trying to get a "lookup number of clicks" function to work in PHP (A
> > language I do not yet really "speak").
>
> > Any debugging help would be appreciated.
>
> > Thanks!
>
> > DwenDoo...@gmail.com
> > For more options, visithttp://groups.google.com/group/bitly-api- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages