-1

im trying to define some variable with the hash of my short link, using bit.ly api:

$['getJSON']('http://api.bit.ly/v3/shorten?login=myusername&apiKey=myapi&longUrl=http://google.com', function (shortlink) {
console['log']('short_url');
e = _shortlink['hash'];

i'm trying to define the "e" variable as the hash of the link. I mean the result of the link is:

{ "status_code": 200, "status_txt": "OK", "data": { "long_url": "http:\/\/google.com\/", "url": "http:\/\/bit.ly\/blabla", "hash": "XXXXX", "global_hash": "YYYYY", "new_hash": 0 } }

as u can see, I need not only to "GET" the "hash" variable, I also need to dig into the "data" result and only then get from it the hash.

I want that my "e" variable will be in the end of the day

e = XXXXXX

what should I do?

thanks alot!

Dairo
  • 822
  • 1
  • 9
  • 22

1 Answers1

1
$.getJSON('http://api.bit.ly/v3/shorten?login=myusername&apiKey=myapi&longUrl=http://google.com', function (response) {
console.log('short_url');
e = response.data.hash;
Wyatt
  • 2,491
  • 15
  • 12
  • Thanks alot! I want to add to your reputation (if it's possible here) , just explain me how :) – Gerbrand Holoy Nov 21 '13 at 20:38
  • The accepted answer and upvote do nicely. Normally you'll want to leave your question so others can benefit from the answer. If you want to respond doing so here in the comments is best. Regards :) – Wyatt Nov 21 '13 at 20:49