开发者

How do I pass or parse that access_token from the Dom to a Variable I can then Store and call for access_token?

With help from others I've gotten to the point where I can see the json return from foursquare but any attempts to call it yield an error.

Essentially, if I'm in Firebug and 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?

Here's the latest code tried.

va开发者_开发知识库r jsonUrl = url +"&callback=?";
var access_token;

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

also tried

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

But when I try and alert(access_token); or run a foursquare api call I get the following errors

Resource interpreted as Script but transferred with MIME type application/json. Uncaught SyntaxError: Unexpected token : checkinsGET https://api.foursquare.com/v2/users/self/checkins?oauth_token=undefined&format=json 401 (Unauthorized)

I feel like its ready and waiting for me to call it, but how on earth do I print it from the Dom into a var that I can use? Been fighting for hours and been trying all my research techniques for some reason this one's elluding me. Thanks for everyone's help so far, I'm really hoping to get passed this!


Try removing the "&callback=?" from the url. I think jQuery adds that for you if you set the dataType to jsonp.

EDIT: from the jquery ajax documentation describing the dataType parameter:

"jsonp": Loads in a JSON block using JSONP. Will add an extra "?callback=?" to the end of your URL to specify the callback.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜