untappd.com の API を使用しようとしています。結果は JSON で返されますが、私はよく知りませんが、XML を使ったことが多くあります。
Chrome のネットワーク タブを見ると、リクエストがキャンセルされたと表示され、さらにエラーは次のとおりです。
Access-Control-Allow-Origin では許可されていません。
私のコードは次のようになります。
$('button').click(function(){
query=$("#query").val();
//Add the seearch term to the base URL and ask for JSON back
$.getJSON(url+query,function(json){
alert(url+query);
//loop through results
$.each(json.results,function(i,beer){
$("#results").append('<p> '+ beer.beer_name + '</p>');
});
});
});
});
編集:
プロキシを使用するのは理にかなっていますが、試してみると何も出力されません。これが私がやったことです、おそらくこれを間違ってフォーマットしています、
#!/usr/bin/perl
use CGI ":standard";
use strict;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
print "Content-type: json\n\n";
my $URL = "http://api.untappd.com/v3/user_distinct?key=KEY_TAKEN_OUT&user=searayman";
my $contents = get($URL);
print $contents;
ブラウザから直接呼び出された場合の JSON 出力:
{"http_code":200,"returned_results":25,"next_page":"http:\/\/api.untappd.com\/v3\/user_distinct?user=searayman&offset=25","results":[{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"17568","brewery_id":"2583","checkin_id":"6708578","beer_type":"Belgian Strong Dark Ale","beer_name":"Mad Elf","brewery_name":"Tr\u00f6egs Brewing Company","created_at":"Sat, 14 Apr 2012 01:35:40 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/6708578","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-troegsMadElf.jpg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"5607","brewery_id":"940","checkin_id":"6706270","beer_type":"American Stout","beer_name":"Oak Barrel Stout","brewery_name":"Old Dominion Brewing Co.","created_at":"Sat, 14 Apr 2012 01:11:30 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/6706270","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-OakBarrelStout_5607.jpeg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"3757","brewery_id":"2583","checkin_id":"6705236","beer_type":"Imperial \/ Double Red Ale","beer_name":"Nugget Nectar","brewery_name":"Tr\u00f6egs Brewing Company","created_at":"Sat, 14 Apr 2012 00:59:59 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/6705236","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-troegNuggetNectar.jpg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"13013","brewery_id":"24","checkin_id":"6547244","beer_type":"Belgian Dubbel","beer_name":"Dubbel","brewery_name":"Allagash Brewing Company","created_at":"Sun, 08 Apr 2012 03:12:14 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/6547244","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-Dubbel_13013.jpeg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"31961","brewery_id":"2583","checkin_id":"6547021","beer_type":"Doppelbock ","beer_name":"Troegenator Doublebock","brewery_name":"Tr\u00f6egs Brewing Company","created_at":"Sun, 08 Apr 2012 03:09:02 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/6547021","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-troegTroegenator.jpg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"18099","brewery_id":"1204","checkin_id":"6167988","beer_type":"American Strong Ale","beer_name":"Arrogant Bastard Ale","brewery_name":"Stone Brewing Co.","created_at":"Tue, 27 Mar 2012 15:40:11 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/6167988","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-arrogantBastardAle.jpg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"31284","brewery_id":"2583","checkin_id":"6167981","beer_type":"Hefeweizen","beer_name":"DreamWeaver Wheat","brewery_name":"Tr\u00f6egs Brewing Company","created_at":"Tue, 27 Mar 2012 15:37:49 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/6167981","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-troegsDreamweaver.jpg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"8596","brewery_id":"507","checkin_id":"5879899","beer_type":"American IPA","beer_name":"Misery Bay IPA","brewery_name":"Erie Brewing Co.","created_at":"Sat, 17 Mar 2012 21:32:46 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/5879899","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-MiseryBayIPA_8596.jpeg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"17686","brewery_id":"4719","checkin_id":"5775347","beer_type":"Belgian Strong Dark Ale","beer_name":"La Torpille","brewery_name":"BFM (Brasserie des Franches-Montagnes)","created_at":"Thu, 15 Mar 2012 00:52:46 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/5775347","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/temp\/badge-beer-default.png"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"5672","brewery_id":"1062","checkin_id":"5483144","beer_type":"American Barleywine","beer_name":"The Vermonster","brewery_name":"Rock Art Brewery","created_at":"Sun, 04 Mar 2012 02:57:45 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/5483144","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/temp\/badge-beer-default.png"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"95236","brewery_id":"609","checkin_id":"5481547","beer_type":"Belgian Pale Ale","beer_name":"Rayon Vert","brewery_name":"Green Flash Brewing Co.","created_at":"Sun, 04 Mar 2012 02:38:33 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/5481547","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-RayonVert_95236.jpeg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"10383","brewery_id":"459","checkin_id":"5479437","beer_type":"American Pale Wheat Ale","beer_name":"Ta Henket","brewery_name":"Dogfish Head Craft Brewery","created_at":"Sun, 04 Mar 2012 02:13:34 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/5479437","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-TaHenket_10383.jpeg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"14098","brewery_id":"1490","checkin_id":"5458703","beer_type":"American IPA","beer_name":"Alimony Ale","brewery_name":"Buffalo Bill's Brewery (California)","created_at":"Sat, 03 Mar 2012 21:18:34 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/5458703","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-AlimonyAle_14098.jpeg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"9806","brewery_id":"1628","checkin_id":"5457154","beer_type":"Imperial \/ Double IPA","beer_name":"Imperial IPA","brewery_name":"Mendocino Brewing Company","created_at":"Sat, 03 Mar 2012 20:48:08 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/5457154","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-ImperialIPA_9806.jpeg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"6373","brewery_id":"609","checkin_id":"5403271","beer_type":"American IPA","beer_name":"West Coast IPA","brewery_name":"Green Flash Brewing Co.","created_at":"Fri, 02 Mar 2012 03:43:52 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/5403271","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-WestCoastIPA_6373.jpeg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"21637","brewery_id":"24","checkin_id":"5400942","beer_type":"Belgian Strong Pale Ale","beer_name":"Victoria Ale","brewery_name":"Allagash Brewing Company","created_at":"Fri, 02 Mar 2012 02:55:55 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/5400942","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/temp\/badge-beer-default.png"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"1382","brewery_id":"1204","checkin_id":"4060691","beer_type":"Imperial \/ Double IPA","beer_name":"Stone Ruination IPA","brewery_name":"Stone Brewing Co.","created_at":"Sun, 08 Jan 2012 15:33:19 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/4060691","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-StoneRuinationIPA.jpg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"4173","brewery_id":"4565","checkin_id":"4060682","beer_type":"American Amber \/ Red Ale","beer_name":"American Amber Ale","brewery_name":"Rogue Ales","created_at":"Sun, 08 Jan 2012 15:31:22 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/4060682","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-rogueAmericanAmberAle.jpg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"80806","brewery_id":"459","checkin_id":"3986144","beer_type":"Belgian Strong Pale Ale","beer_name":"Pearl Jam Twenty Faithfull Ale","brewery_name":"Dogfish Head Craft Brewery","created_at":"Fri, 06 Jan 2012 00:30:05 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/3986144","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-PearlJamTwentyFaithfullAle_80806.jpeg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"6392","brewery_id":"360","checkin_id":"3931927","beer_type":"Vienna Lager","beer_name":"Dos Equis Ambar","brewery_name":"Cervecer\u00eda Cuauht\u00e9moc Moctezuma","created_at":"Mon, 02 Jan 2012 05:29:30 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/3931927","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-CerveceriaDosEquisAmber.jpg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"1553","brewery_id":"94","checkin_id":"3807056","beer_type":"American IPA","beer_name":"Racer 5","brewery_name":"Bear Republic Brewing Co.","created_at":"Thu, 29 Dec 2011 15:28:15 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/3807056","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-BearRepublicRacer5.jpg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"11430","brewery_id":"4586","checkin_id":"3660723","beer_type":"Winter Ale","beer_name":"Old Man Winter Ale","brewery_name":"Southern Tier Brewing Company","created_at":"Fri, 23 Dec 2011 19:53:29 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/3660723","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-southernTierOldMan.jpg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"6284","brewery_id":"1142","checkin_id":"3606330","beer_type":"American Pale Ale","beer_name":"Pale Ale","brewery_name":"Sierra Nevada Brewing Co.","created_at":"Tue, 20 Dec 2011 22:52:02 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/3606330","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-PaleAle_6284.jpeg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"59162","brewery_id":"459","checkin_id":"3596239","beer_type":"Imperial \/ Double IPA","beer_name":"120 Minute IPA (2011)","brewery_name":"Dogfish Head Craft Brewery","created_at":"Tue, 20 Dec 2011 01:30:25 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/3596239","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-dfh120minuteIPA.jpg"},{"user":{"uid":"23305","user_name":"searayman","first_name":"Mike","last_name":"J.","user_avatar":"http:\/\/gravatar.com\/avatar.php?gravatar_id=cc0d3298f9b2754988e95cca7dceea94&rating=X&size=80&default=https:\/\/untappd.s3.amazonaws.com\/site\/assets\/images\/default_avatar.jpg","location":"Annapolis, MD","bio":"","is_friends":null,"url":""},"beer_id":"25796","brewery_id":"765","checkin_id":"3553391","beer_type":"American Pale Wheat Ale","beer_name":"A Little Sumpin' Sumpin' Ale","brewery_name":"Lagunitas Brewing Company","created_at":"Sun, 18 Dec 2011 00:10:35 +0000","checkin_link":"http:\/\/untappd.com\/user\/searayman\/checkin\/3553391","beer_stamp":"https:\/\/untappd.s3.amazonaws.com\/site\/beer_logos\/beer-lagunitasLittleSumpinSumpin.jpg"}]}