开发者

How do I extract a foursquare access_token saved to DOM as a link so I can use it for API calls?

开发者 https://www.devze.com 2023-03-15 19:11 出处:网络
The code looks like: var jsonUrl = url +\"&callback=?\"; //$(\"#getJSON\").click(function(){ $.getJSON(

The code looks like:

    var jsonUrl = url +"&callback=?";
//  $("#getJSON").click(function(){
            $.getJSON(
                jsonUrl,
                {
    dataType: "JSONP"
  },                
                function(json){ var items = [];
                var items = JSON.parse(json);
                alert(items);


                    $("#result").html("<h3>" + result + "</h3>");



                }  
        );

also tried

$.ajax({

    type: 'GET',   

    url: url,
    key: $('#access_token'),
    dataType: 'jsonp',
    success: function(data){ $('.result').html(data);
        processData: false,

        alert(jQuery.data( document.access_token ));
         alert(data[0].text);},
    error: function() {
        console.log('Uh Oh!'); },
    jsonp:'onJSONPLoad'

    });

Essentially if I'm in Firebug an开发者_高级运维d look at the net objects I see the status 200

If I click on the JSON tab I can see my access_token, but how do I extract it from there so I can use for API calls?


var jsonUrl = url +"&callback=?";
var access_token;

$("#getJSON").click(function() {
    $.getJSON(jsonUrl, { dataType: "JSONP" }, function(json){ 
        ...
        access_token = json.access_token;
        ...
    });
});

// do something with your access_token ?

Did i understand your question right? You can assign the the access_token to a variable and then do what you want with it in your code, can't you?

$.ajax({
  dataType: 'jsonp',
  jsonp: 'callback',
  url: url,
  success: function (json) {
    console.log(json.access_token);
  }
});
0

精彩评论

暂无评论...
验证码 换一张
取 消