{"id":764,"date":"2014-07-19T04:43:34","date_gmt":"2014-07-19T01:43:34","guid":{"rendered":"http:\/\/metehantoksoy.com\/?p=764"},"modified":"2014-07-19T04:43:34","modified_gmt":"2014-07-19T01:43:34","slug":"c-ile-foursquare-api","status":"publish","type":"post","link":"https:\/\/metehantoksoy.com\/?p=764","title":{"rendered":"C# ile Foursquare API Kullanarak Uygulama Geli\u015ftirme"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/www.cision.com\/us\/wp-content\/uploads\/2013\/08\/fourscquare.png\" alt=\"foursquare logo\" width=\"705\" height=\"344\" \/><\/p>\n<p style=\"text-align:justify;\">Merhabalar. Uzunca bir aradan sonra blog yazmaya yeni f\u0131rsat buldum ve \u00f6\u011frendi\u011fim bir \u015feyi sizlerle payla\u015f\u0131yorum. Umar\u0131m yararl\u0131 olur.<\/p>\n<p style=\"text-align:justify;\">Bug\u00fcnk\u00fc konumuz <strong>C# .Net ile <a title=\"Foursquare\" href=\"https:\/\/tr.foursquare.com\/\" target=\"_blank\">Foursquare <\/a>API<\/strong>. \u00a0Windows Phone 8 geli\u015ftirdi\u011fim <strong>Sade Kahve<\/strong> uygulamama ne zamand\u0131r eklemek isteyip eklemeye vakit bulamad\u0131\u011f\u0131m en yak\u0131n kahve d\u00fckkan\u0131n\u0131 bulma \u00f6zelli\u011fini sonunda ekledim. Sizin konumunuzu al\u0131p, Bing Maps ile sizi, listeledi\u011fi kahve d\u00fckkanlar\u0131 aras\u0131ndan se\u00e7ti\u011finiz kahve d\u00fckkan\u0131na y\u00f6nlendiriyor. Uygulaman\u0131n linkine <a title=\"Sade Kahve Windows Phone Store'da !\" href=\"http:\/\/www.windowsphone.com\/tr-tr\/store\/app\/sade-kahve\/01353381-ac74-409e-aac8-66b681fa6a7d\" target=\"_blank\">buraya <\/a>t\u0131klayarak ula\u015fabilirsiniz.<\/p>\n<p style=\"text-align:justify;\"><!--more--><\/p>\n<p style=\"text-align:justify;\">\u00d6ncelikle neden <a title=\"NuGet Galerisi\" href=\"https:\/\/www.nuget.org\/\" target=\"_blank\"><strong>NuGet<\/strong> <\/a>paketlerden <a title=\"SharpSquare on NuGet Library\" href=\"https:\/\/www.nuget.org\/packages\/SharpSquare\/\" target=\"_blank\"><strong>SharpSquare<\/strong><\/a> kullanmad\u0131\u011f\u0131m\u0131 s\u00f6yleyerek ba\u015flayay\u0131m. K\u00fct\u00fcphaneyi kullan\u0131rken &#8220;<strong>TargetInvocationException<\/strong>&#8221; \u00a0hatas\u0131 ald\u0131m ve ne yapt\u0131ysam bu hatay\u0131 \u00e7\u00f6zemedim. Bu benim hatam da olabilir, k\u00fct\u00fcphanenin Windows Phone 8.1 ile ufak tefek uyumsuzuklar\u0131 varsa ondan da kaynaklan\u0131yor olabilir. Sade Kahve uygulamam\u0131n g\u00fcncellemesini geciktirmemek ve kullan\u0131c\u0131 yorumlar\u0131ndaki istekleri bir an \u00f6nce ger\u00e7ekle\u015ftirmek ad\u0131na bu hatayla oyalanmad\u0131m ve <strong>WebAPI<\/strong> kullanmaya ba\u015flad\u0131m. Bundan dolay\u0131 bende sorgular\u0131m\u0131 kendimin atabildi\u011fi k\u00fc\u00e7\u00fck bir fonksiyon yazd\u0131m. Yaz\u0131n\u0131n ilerleyen k\u0131s\u0131mlar\u0131nda \u00f6rnek kodu\u00a0sizlerle payla\u015f\u0131yor olaca\u011f\u0131m. Foursquare API kullan\u0131m\u0131n\u0131 ba\u015ftan itibaren anlatmaya ba\u015fl\u0131yorum.<\/p>\n<h2 style=\"text-align:justify;\"><span style=\"color:#008080;\"><strong>\u00a01. Foursquare API&#8217;ya Kay\u0131t Olma ve ClientID ile ClientSecretID&#8217;nin al\u0131nmas\u0131.<\/strong><\/span><\/h2>\n<p style=\"text-align:justify;\">1-)\u00a0\u00d6ncelikle Foursquare \u00fczerinden uygulaman\u0131z\u0131 kay\u0131t ettirmeniz ve uygulaman\u0131za ait\u00a0<strong>ClientID<\/strong> ve <strong>ClientSecretID<\/strong>&#8216;nizi alman\u0131z gerekmektedir. Bunun i\u00e7in de<a title=\"Fourquare Developer \" href=\"https:\/\/developer.foursquare.com\/\" target=\"_blank\"> \u015fu linke<\/a> t\u0131klayarak a\u015fa\u011f\u0131daki i\u015flemleri yapman\u0131z gerekmektedir.<\/p>\n<p style=\"text-align:justify;\"><a href=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen11.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-774\" src=\"http:\/\/metehantoksoy.wordpress.com\/wp-content\/uploads\/2014\/07\/screen11.jpg?w=585\" alt=\"Screen1\" width=\"585\" height=\"349\" srcset=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen11.jpg 1003w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen11-300x179.jpg 300w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen11-768x459.jpg 768w\" sizes=\"auto, (max-width: 585px) 85vw, 585px\" \/><\/a><\/p>\n<p style=\"text-align:justify;\"><a href=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen1.jpg\"><br \/>\n<\/a>2-) Hesab\u0131n\u0131za giri\u015f yapman\u0131z\u0131 isteyebilir. Giri\u015f yapt\u0131ktan sonra Sa\u011f Tarafta bulunan &#8220;<strong>Yeni Bir Uygulama Olu\u015ftur<\/strong>&#8220;a T\u0131klay\u0131n.<\/p>\n<p style=\"text-align:justify;\"><a href=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen2jpg.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-775\" src=\"http:\/\/metehantoksoy.wordpress.com\/wp-content\/uploads\/2014\/07\/screen2jpg.jpg?w=585\" alt=\"Screen2JPG\" width=\"585\" height=\"357\" srcset=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen2jpg.jpg 978w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen2jpg-300x183.jpg 300w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen2jpg-768x469.jpg 768w\" sizes=\"auto, (max-width: 585px) 85vw, 585px\" \/><\/a><\/p>\n<p style=\"text-align:justify;\">3-) Uygulaman\u0131za ait bilgileri doldurduktan sonra en a\u015fa\u011f\u0131da bulunan &#8220;<strong>De\u011fi\u015fikleri Kaydet<\/strong>&#8220;e t\u0131klay\u0131n.<\/p>\n<p style=\"text-align:justify;\"><a href=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-776\" src=\"http:\/\/metehantoksoy.wordpress.com\/wp-content\/uploads\/2014\/07\/screen3.jpg?w=585\" alt=\"Screen3\" width=\"585\" height=\"381\" srcset=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen3.jpg 976w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen3-300x196.jpg 300w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen3-768x501.jpg 768w\" sizes=\"auto, (max-width: 585px) 85vw, 585px\" \/><\/a><\/p>\n<p style=\"text-align:justify;\">4-) Gerekli bilgileri kaydettikten sonra a\u00e7\u0131lan sayfa a\u015fa\u011f\u0131daki gibi olacakt\u0131r ve size uygulaman\u0131zla ilgili bilgiler verecektir. <strong>ClientID<\/strong> ve <strong>ClientSecret<\/strong>, uygulaman\u0131za ve size ait <strong>gizli<\/strong> bir bilgidir ve bu bilgiyi <strong>sakl\u0131<\/strong> tutmal\u0131s\u0131n\u0131z.<\/p>\n<p style=\"text-align:justify;\"><a href=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen4.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-777\" src=\"http:\/\/metehantoksoy.wordpress.com\/wp-content\/uploads\/2014\/07\/screen4.jpg?w=585\" alt=\"Screen4\" width=\"585\" height=\"385\" srcset=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen4.jpg 977w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen4-300x197.jpg 300w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen4-768x505.jpg 768w\" sizes=\"auto, (max-width: 585px) 85vw, 585px\" \/><\/a><\/p>\n<p style=\"text-align:justify;\">Foursquare&#8217;da kay\u0131t olmay\u0131 tamamlad\u0131k. \u015eimdi istedi\u011fimiz verileri <strong>WebAPI<\/strong> ile alma zaman\u0131.<\/p>\n<h2 style=\"text-align:justify;\"><span style=\"color:#008080;\"><strong>2. C# ile Foursquare API&#8217;dan Veri \u00c7ekmek.<\/strong><\/span><\/h2>\n<h4 style=\"text-align:justify;\"><span style=\"color:#ff0000;\">Ba\u015flamadan \u00f6nce:\u00a0<\/span><\/h4>\n<p style=\"text-align:justify;\">\u00d6ncelikle bilmeni gereken baz\u0131 <strong>limitler<\/strong> mevcut. Bu limitlerden biraz bahsetmenin gerekli oldu\u011funu d\u00fc\u015f\u00fcn\u00fcyorum.<\/p>\n<p style=\"text-align:justify;\"><a title=\"Foursquare API - Rate Limits\" href=\"https:\/\/developer.foursquare.com\/overview\/ratelimits\" target=\"_blank\">\u015eu linkte<\/a> anlat\u0131ld\u0131\u011f\u0131 gibi, Foursquare API&#8217;\u0131n belirli bir sorgu limiti mevcut. Fakat bu limit \u00e7ok d\u00fc\u015f\u00fck de\u011fil.<\/p>\n<p style=\"text-align:justify;\"><span style=\"color:#800080;\"><span style=\"color:#800000;\">Uygulaman\u0131z\u0131n<\/span>;<\/span><\/p>\n<p style=\"text-align:justify;\">Kullan\u0131c\u0131 giri\u015fi yap\u0131lmadan sadece mekan sorgusunun saatlik 5000 sorgu limiti mevcut.<\/p>\n<p style=\"text-align:justify;\">Kullan\u0131c\u0131 giri\u015fi yap\u0131lacak ise giri\u015f yap\u0131lan her hesap i\u00e7in saatte <strong>500<\/strong> sorgu limitiniz var. \u015e\u00f6yle de s\u00f6ylenebilir. <strong>OAuthtoken<\/strong> kullanarak, yani kullan\u0131c\u0131 giri\u015fi yap\u0131lm\u0131\u015f bir \u015fekilde her kullan\u0131c\u0131 i\u00e7in 500 sorgu limitiniz var. Yani kendi hesab\u0131yla uygulaman\u0131zda oturum a\u00e7an kullan\u0131c\u0131n\u0131z, saatte <strong>maksimum<\/strong> 500 check-in yapabilir veya 100 check-in + 400 mekan sorgusu yapabilir. E\u011fer 4 kullan\u0131c\u0131n\u0131z var ise her kullan\u0131c\u0131 i\u00e7in 500 olmak \u00fczere <strong>2000<\/strong> sorgu hakk\u0131n\u0131z olur. Fakat bir kullan\u0131c\u0131n\u0131n sorgu hakk\u0131 ba\u015fka bir kullan\u0131c\u0131ya aktar\u0131lamaz. Her kullan\u0131c\u0131 maksimum 500 sorgu yapabilir.<\/p>\n<p style=\"text-align:justify;\">Kullan\u0131c\u0131 giri\u015fi olmadan ise <strong>5000\u00a0<\/strong>sorgu atabilirsiniz. \u00d6rne\u011fin saatte <strong>2500<\/strong> <strong>mekan aramas\u0131<\/strong> yap\u0131p art\u0131 <strong>2500 mekan \u00f6nerisi<\/strong> alabilirsiniz. Burada k\u00fc\u00e7\u00fck bir ipucu verecek olursam, kullan\u0131c\u0131s\u0131z yapabilece\u011finiz her\u015feyi kullan\u0131c\u0131n\u0131n OAuthtoken&#8217;ini kullanmadan yap\u0131n. Bunun i\u00e7in iyi analiz yapmal\u0131s\u0131n\u0131z. \u00d6rne\u011fin mekan sorgusu kullan\u0131c\u0131 OAuthToken&#8217;i olmadan yap\u0131l\u0131yor fakat e\u011fer hem OAuthtoken ile hem de kullan\u0131c\u0131 olmadan yap\u0131l\u0131yorsa, uygulaman\u0131z\u0131n s\u00fcreklili\u011fi i\u00e7in <strong>kesinlikle kullan\u0131c\u0131s\u0131z sorguyu<\/strong> tercih etmeniz gerekir. Yoksa kullan\u0131c\u0131lar\u0131n\u0131z kendilerini Foursquare API limitine tak\u0131lm\u0131\u015f olarak bulabilirler.<\/p>\n<h4 style=\"text-align:justify;\"><span style=\"color:#ff0000;\">API Kullan\u0131m\u0131 ve Veri Tipleri:<\/span><\/h4>\n<p style=\"text-align:justify;\">Bu uzunca dipnottan sonra kodlamaya ge\u00e7iyorum. Herhangi bir s\u0131k\u0131nt\u0131 olu\u015fmas\u0131 durumunda <strong>yorum<\/strong> veya <strong>eposta<\/strong> ile soru sorabilirsiniz ve dedi\u011fim gibi yaz\u0131n\u0131n sonunda Windows Phone 8.1 i\u00e7in haz\u0131rlanm\u0131\u015f \u00f6rnek projeyi\u00a0bulabilirsiniz.<\/p>\n<p style=\"text-align:justify;\">\u00d6rnek senaryo olarak, telefonun <strong>konum<\/strong> bilgisini kullanarak etraf\u0131m\u0131zda <strong>1 kilometre<\/strong> etraf\u0131m\u0131zda yer alan b\u00fct\u00fcn <strong>restoranlar\u0131n<\/strong> listesini \u00e7ekip, bunu DataTempletini tan\u0131mlad\u0131\u011f\u0131m\u0131z ListView \u00fczerinde g\u00f6sterece\u011fiz.<\/p>\n<p style=\"text-align:justify;\">\u00d6ncelikle Foursquare API, &#8220;<strong>GET<\/strong>&#8221; methodu ile \u00e7al\u0131\u015f\u0131yor ve &#8220;<strong>Json<\/strong>&#8221; \u00a0tipinde veri d\u00f6nd\u00fcr\u00fcyor. Json tipi ile ilgili detayl\u0131 bilgiyi bu <a title=\"Json Nedir? \" href=\"http:\/\/json.org\/json-tr.html\" target=\"_blank\">linke\u00a0<\/a>t\u0131klayarak \u00f6\u011frenebilirsiniz.<\/p>\n<p style=\"text-align:justify;\">Bizim API&#8217;dan veri \u00e7ekebilmemiz i\u00e7in gereken <strong>ClientID<\/strong> ve <strong>ClienSecretID<\/strong>&#8216;yi yaz\u0131n\u0131n \u00fcst tarafnda alm\u0131\u015ft\u0131k. Ayn\u0131 zamanda \u00f6rnek kodda kullanca\u011f\u0131m\u0131z <strong>yemek<\/strong> <strong>kategorisinin<\/strong> kodunu, arama yapaca\u011f\u0131m\u0131z <strong>\u00e7emberin b\u00fcy\u00fckl\u00fc\u011f\u00fcn\u00fc<\/strong> ve <strong>API&#8217;in adresini<\/strong> , program s\u0131ras\u0131nda gerekli yerlerde kullanmak ve kodun <strong>okunabilirli\u011fini ar\u0131tmak<\/strong> \u00fczere \u00a0&#8220;<span style=\"color:#003366;\">const string<\/span>&#8221; olarak tan\u0131ml\u0131yoruz.<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#008080;\">public const string<\/span> <span style=\"color:#800000;\">clientID\u00a0<\/span>=<span style=\"color:#993300;\"> &#8220;Client ID&#8217;nizi buraya yaz\u0131n.&#8221;<\/span>;<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#008080;\">public const string<\/span> <span style=\"color:#800000;\">clientSecret <\/span>=<span style=\"color:#993300;\"> &#8220;Client Secret kodunuzu buraya yaz\u0131n.&#8221;<\/span>;<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#008080;\">public const string<\/span> <span style=\"color:#800000;\">foodCode <\/span>=<span style=\"color:#993300;\"> &#8220;4d4b7105d754a06374d81259&#8221;<\/span>;<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#008080;\">public const string<\/span>\u00a0<span style=\"color:#800000;\">apiUrl<\/span> =<span style=\"color:#993300;\"> &#8220;https:\/\/api.foursquare.com\/v2\/venues\/search?&#8221;<\/span>;<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#008080;\">public const int<\/span> <span style=\"color:#800000;\">radius <\/span>= 1000;<\/p>\n<p style=\"text-align:justify;\">B\u00fct\u00fcn kategorilerin kodlar\u0131n\u0131n bulundu\u011fu listeye \u015fu linkten ula\u015fabilirsiniz: <a title=\"Foursquare API Kategori Listesi\" href=\"https:\/\/developer.foursquare.com\/categorytree\" target=\"_blank\">Foursquare API Category Hierarchy<\/a>.<\/p>\n<p style=\"text-align:justify;\">API&#8217;a sorguyu <strong>HttpClient<\/strong> arac\u0131l\u0131\u011f\u0131 ile, istedi\u011fimiz de\u011ferleri <strong>apiUrl<\/strong> de\u011fi\u015fkeninin sonuna ekleyerek ataca\u011f\u0131z. Yani API&#8217;dan geri d\u00f6nen cevab\u0131 biz istedi\u011fimiz gibi \u00f6zelle\u015ftirebiliyoruz. Mesela etrafta sadece belirli kategoriden veya belirli bir alan i\u00e7indeki veya isminde\u00a0istedi\u011fimiz kelimelerin ge\u00e7ece\u011fi mekanlar\u0131 listeletebiliriz. B\u00fct\u00fcn sorgulama kriterleri i\u00e7in \u015fu linke t\u0131klayabilirsiniz: <a title=\"API Mekan Arama Parametreleri\" href=\"https:\/\/developer.foursquare.com\/docs\/venues\/search\" target=\"_blank\">Foursquare API Venues Search Parameters<\/a><\/p>\n<p style=\"text-align:justify;\">\u00d6rnek projemizde dedi\u011fimiz gibi biz &#8220;<strong>Yemek<\/strong>&#8221; kategorisinden, cihaz\u0131n konumunun 1 kilometre &#8220;<strong>Yak\u0131n\u0131nda<\/strong>&#8220;ki b\u00fct\u00fcn mekanlar\u0131 \u00e7ekmek istiyoruz. Bu durumda yapacaklar\u0131m\u0131z \u015funlar\u0131r:<\/p>\n<p style=\"text-align:justify;\">Windows Phone 8.1 cihaz\u0131m\u0131n\u0131n konum bilgisine ihtiyac\u0131m\u0131z var. Bunun i\u00e7in <strong>package.appxmanifest<\/strong> dosyas\u0131n\u0131 a\u00e7\u0131p, cihaz\u0131n <strong>Konum<\/strong> (<strong>Location<\/strong>)\u00a0bilgisine ve <strong>internete<\/strong> eri\u015fimi i\u00e7in izinlerini al\u0131yoruz.<\/p>\n<p style=\"text-align:justify;\"><a href=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen5.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-778\" src=\"http:\/\/metehantoksoy.wordpress.com\/wp-content\/uploads\/2014\/07\/screen5.jpg?w=585\" alt=\"Screen5\" width=\"585\" height=\"385\" srcset=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen5.jpg 906w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen5-300x198.jpg 300w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen5-768x506.jpg 768w\" sizes=\"auto, (max-width: 585px) 85vw, 585px\" \/><\/a><\/p>\n<p style=\"text-align:justify;\">\u0130zinler ald\u0131ktan sonra, konum bilgisini alaca\u011f\u0131m\u0131z objemizi tan\u0131mlay\u0131p hemen konum bilgisini al\u0131yoruz.<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#0000ff;\"> Geoposition<\/span> <span style=\"color:#800000;\">position<\/span> = <span style=\"color:#003366;\">await<\/span> <span style=\"color:#333300;\">new<\/span> <span style=\"color:#0000ff;\">Geolocator().<span style=\"color:#333333;\">GetGeopositionAsync()<\/span><\/span><span style=\"color:#333333;\">;<\/span><\/p>\n<p style=\"text-align:justify;\">Konum bilgisini ald\u0131ktan sonra kodun okunabilirli\u011fini art\u0131rmak i\u00e7in, cihaz\u0131n konumunun enlem derecesinin <strong>latitude<\/strong>\u00a0, boylam derecesinin <strong>longitude<\/strong>\u00a0de\u011fi\u015fkeninde saklayaca\u011f\u0131z. Bunlar <strong>position<\/strong>\u00a0objesinin i\u00e7inde <strong>double<\/strong>\u00a0tipinde saklanmaktad\u0131r. Fakat bizim &#8220;<strong>string<\/strong>&#8220;e ihtiyac\u0131m\u0131z oldu\u011fu i\u00e7in <strong>ToString()<\/strong>\u00a0methodu ile string&#8217;e \u00e7eviriyoruz.<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#008080;\">string<\/span> <span style=\"color:#800000;\">latitude<\/span> = <span style=\"color:#800000;\">position<\/span>.Coordinate.Latitude.ToString();<br \/>\n<span style=\"color:#008080;\">string<\/span> <span style=\"color:#800000;\">longitude<\/span> = <span style=\"color:#800000;\">position<\/span>.Coordinate.Longitude.ToString();<\/p>\n<p style=\"text-align:justify;\">Art\u0131k her \u015fey haz\u0131r oldu\u011funa g\u00f6re\u00a0sorguda kullanaca\u011f\u0131m\u0131z <strong>URL<\/strong>&#8216;i olu\u015fturmaya ba\u015flayabiliriz. Kullan\u0131c\u0131 giri\u015fi olmadan ataca\u011f\u0131m\u0131z her\u00a0sorguda olmas\u0131 gerekenler <strong>clientId<\/strong>, <strong>clientSecret<\/strong> ve <strong>tarihtir<\/strong>. \u0130lk olarak her sorguda olmas\u0131 gereken de\u011ferleri <strong>queryUrl<\/strong>\u00a0de\u011fi\u015fkenimize ekleyelim. Her ekledi\u011fimiz iki paremetre aras\u0131nda <strong>and<\/strong>\u00a0anlam\u0131nda olan <strong>&amp;<\/strong>\u00a0i\u015faretini koyuyoruz.<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#008080;\">string<\/span> <span style=\"color:#800000;\">queryUrl<\/span> = <span style=\"color:#800000;\">url<\/span>;<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#800000;\">queryUrl<\/span> +=<span style=\"color:#993300;\"> &#8220;client_id=&#8221;<\/span>+ <span style=\"color:#800000;\">clientID<\/span>;<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#800000;\">queryUrl<\/span> += <span style=\"color:#993300;\">&#8220;&amp;client_secret=&#8221;<\/span> + <span style=\"color:#800000;\">clientSecret<\/span>;<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#800000;\">queryUrl<\/span> +=\u00a0<span style=\"color:#993300;\">&#8220;&amp;v=&#8221;<\/span> + <span style=\"color:#0000ff;\">String<\/span>.Format(<span style=\"color:#993300;\">&#8220;{0:yyyyMMdd}&#8221;<\/span>, <span style=\"color:#0000ff;\">DateTime<\/span>.Now);<\/p>\n<p style=\"text-align:justify;\">\u015eimdi istedi\u011fimiz kriterleri ekliyoruz. Bunlar, cihaz\u0131n konumu ve bu konumun 1 kilometre etraf\u0131ndaki restoranlard\u0131. Bunun i\u00e7in Foursquare API&#8217;\u0131n parametre tablosundan yararlanarak <strong>queryUrl\u00a0string<\/strong>ine ekliyoruz.<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#800000;\">queryUrl<\/span> += <span style=\"color:#993300;\">&#8220;&amp;ll=&#8221;<\/span>+<span style=\"color:#800000;\">latitude<\/span> + &#8220;,&#8221; + <span style=\"color:#800000;\">longitude<\/span>;<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#800000;\">queryUrl<\/span> += <span style=\"color:#993300;\">&#8220;&amp;radius=&#8221;<\/span> + <span style=\"color:#800000;\">radius<\/span>.ToString();<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#800000;\">queryUrl<\/span> += <span style=\"color:#993300;\">&#8220;&amp;categoryId=&#8221;<\/span> + <span style=\"color:#800000;\">foodCode\u00a0<\/span>;<\/p>\n<p style=\"text-align:justify;\">Adresimiz art\u0131k bize istedi\u011fimiz de\u011feri d\u00f6nd\u00fcrmeye haz\u0131r ve <strong>queryUrl,<\/strong>\u00a0<strong>string<\/strong> de\u011fi\u015fkeni i\u00e7inde saklan\u0131yor. Art\u0131k API&#8217;dan <strong>JSON<\/strong> tipindeki sorgu sonucunu \u00e7ekme zaman\u0131.<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#0000ff;\">HttpClient<\/span> <span style=\"color:#800000;\">client<\/span> = new <span style=\"color:#0000ff;\">HttpClient<\/span>();<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#008080;\">string\u00a0<\/span><span style=\"color:#800000;\">jsonString<\/span> =\u00a0<span style=\"color:#003366;\">await<\/span> <span style=\"color:#800000;\">client<\/span>.GetStringAsync(<span style=\"color:#800000;\">queryUrl\u00a0<\/span>);<\/p>\n<p style=\"text-align:justify;\">Art\u0131k elimizde <strong>JSON<\/strong> format\u0131nda istedi\u011fimiz ver mevcut, fakat bizim bunu kullanabilece\u011fimiz bir formata <strong>d\u00f6nd\u00fcrmemiz<\/strong> gerekmektedir. JSON&#8217;u string olarak ele al\u0131p tek tek <strong>parse<\/strong> edebilirsiniz fakat bu <strong>gereksiz<\/strong> u\u011fra\u015f olacakt\u0131r. \u00a0Bunun i\u00e7in JSON verilerini belirli bir obje tipine d\u00f6nd\u00fcren <strong>Newtonsof.Json.JsonCovert<\/strong> methodunu kullanaca\u011f\u0131z. Fakat \u00f6ncelikle bu JSON verisine kar\u015f\u0131l\u0131k gelen class yap\u0131s\u0131na ihtiyac\u0131m\u0131z var. Bunun i\u00e7in \u00a0d\u00f6nen JSON verisini\u00a0<a title=\"JSON to C#\" href=\"http:\/\/json2csharp.com\/\" target=\"_blank\">http:\/\/json2csharp.com\/<\/a> adresine\u00a0yap\u0131\u015ft\u0131r\u0131p &#8220;<strong>Generate<\/strong>&#8221; butonuna basmam\u0131z yeterli \u00a0veya uzun uzun kendi elinizle de yazabilirsiniz class&#8217;\u0131n\u0131z\u0131. Se\u00e7im sizin.<\/p>\n<p style=\"text-align:justify;\">Bu siteden d\u00f6nen class yap\u0131s\u0131n\u0131 tek bir class alt\u0131nda tan\u0131mlad\u0131m. Yani \u00f6nce &#8220;<strong>Foursquare<\/strong>&#8221; ad\u0131nda bir class tan\u0131mlay\u0131p, siteden ald\u0131\u011f\u0131m class yap\u0131s\u0131n\u0131 &#8220;Foursquare&#8221; class&#8217;\u0131m\u0131n i\u00e7ine yap\u0131\u015ft\u0131rd\u0131m. B\u00f6ylelikle okunabilirlik a\u00e7\u0131s\u0131ndan avantajl\u0131 olarak b\u00fct\u00fcn elementlere &#8220;<strong>Foursquare.bla<\/strong>&#8221; \u015feklinde ula\u015faca\u011f\u0131m. Siteden elde edilmi\u015f class yap\u0131s\u0131n\u0131 ekteki projeden bulabilirsiniz.<\/p>\n<p style=\"text-align:justify;\">Bundan sonras\u0131 \u00e7ok basit. \u00d6ncelikle <strong>Newtonsoft.Json<\/strong> s\u0131n\u0131f\u0131n\u0131 projemize ekleyelim. Bunun i\u00e7in;<\/p>\n<p style=\"text-align:justify;\">1.) <strong>Solution Explorer<\/strong>&#8216;da bulunan <strong>References&#8217;<\/strong>a sa\u011f t\u0131k yaparak <strong>Manage NuGet Packs&#8217;<\/strong>\u00a0i se\u00e7elim.<\/p>\n<p style=\"text-align:justify;\"><a href=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen6.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-779\" src=\"http:\/\/metehantoksoy.wordpress.com\/wp-content\/uploads\/2014\/07\/screen6.jpg\" alt=\"Screen6\" width=\"381\" height=\"251\" srcset=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen6.jpg 381w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen6-300x198.jpg 300w\" sizes=\"auto, (max-width: 381px) 85vw, 381px\" \/><\/a><\/p>\n<p style=\"text-align:justify;\">2.) Arama yerine &#8220;<strong>Newtonsoft<\/strong>&#8221; yazarak \u00e7\u0131kan &#8220;<strong>Json.Net<\/strong>&#8221; framework\u00fcn\u00fc projemize ekleyelim.<\/p>\n<p style=\"text-align:justify;\"><a href=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen7.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-780\" src=\"http:\/\/metehantoksoy.wordpress.com\/wp-content\/uploads\/2014\/07\/screen7.jpg?w=585\" alt=\"Screen7\" width=\"585\" height=\"390\" srcset=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen7.jpg 898w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen7-300x200.jpg 300w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen7-768x513.jpg 768w\" sizes=\"auto, (max-width: 585px) 85vw, 585px\" \/><\/a><\/p>\n<p style=\"text-align:justify;\">3.) Y\u00fckleme tamamland\u0131ktan sonra, ekran\u0131n\u0131zda &#8220;<strong>Json.Net<\/strong>&#8221; yan\u0131nda a\u015fa\u011f\u0131daki gibi bir onay i\u015fareti g\u00f6receksiniz.<\/p>\n<p style=\"text-align:justify;\"><a href=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen8.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-781\" src=\"http:\/\/metehantoksoy.wordpress.com\/wp-content\/uploads\/2014\/07\/screen8.jpg?w=585\" alt=\"Screen8\" width=\"585\" height=\"388\" srcset=\"https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen8.jpg 900w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen8-300x199.jpg 300w, https:\/\/metehantoksoy.com\/wp-content\/uploads\/2014\/07\/screen8-768x509.jpg 768w\" sizes=\"auto, (max-width: 585px) 85vw, 585px\" \/><\/a><\/p>\n<p style=\"text-align:justify;\">Projemize<strong>\u00a0Json.Net<\/strong> framework\u00fcn\u00fc ve dolay\u0131s\u0131yla ihtiyac\u0131m\u0131z olan\u00a0<strong>Newtonsoft.Json<\/strong> s\u0131n\u0131f\u0131n\u0131 eklemi\u015f olduk.<\/p>\n<p style=\"text-align:justify;\">Elimizde &#8220;<strong>Foursquare<\/strong>&#8221; ad\u0131yla, API&#8217;dan ald\u0131\u011f\u0131m\u0131z JSON&#8217;a <strong>\u00f6zel<\/strong> <strong>s\u0131n\u0131f\u0131m\u0131z<\/strong> da var. Art\u0131k parse zaman\u0131. \u0130\u015fi &#8220;Newtonsoft.Json&#8221; s\u0131n\u0131f\u0131n\u0131n\u0131n &#8220;<strong>JsonConvert.DeserializeObject<\/strong>&#8221; methoduna b\u0131rakma zaman\u0131.<\/p>\n<p style=\"padding-left:30px;text-align:justify;\"><span style=\"color:#0000ff;\">Foursquare<\/span> <span style=\"color:#800000;\">returnValue<\/span> =\u00a0<span style=\"color:#0000ff;\">JsonConvert<\/span>.DeserializeObject&lt;<span style=\"color:#0000ff;\">Foursquare<\/span>&gt;(<span style=\"color:#800000;\">jsonString<\/span>);<\/p>\n<p style=\"text-align:justify;\">Bundan sonras\u0131 art\u0131k sizin marifetiniz. &#8221; <strong>returnValue.location.distance<\/strong> &#8221; kullanarak kullan\u0131c\u0131ya mesafe mi s\u00f6ylersiniz, kullan\u0131c\u0131y\u0131 BingMap kullanarak y\u00f6nlendir misiniz oras\u0131 sizin.<\/p>\n<p style=\"text-align:justify;\">Dedi\u011fim gibi herhangi bir sorunuz olursa bana e-posta veya buraya yorum yazarak ula\u015fabilirsiniz. Elimden geldi\u011fince yard\u0131mc\u0131 olmaya \u00e7al\u0131\u015f\u0131r\u0131m.<\/p>\n<p style=\"text-align:justify;\">Dip Not: Derleme s\u0131ras\u0131nda &#8220;<strong>Cannot find type System.ComponentModel.PropertyDescriptor in module System.dll<\/strong>&#8221; hatas\u0131 alanlar, Json.Net&#8217;i &#8220;<strong>Manage NuGet Packagets<\/strong>&#8221; ile kurmam\u0131\u015f ve internetten buldu\u011fu &#8220;Newtonsoft.Json.dll&#8221; \u00a0dosyas\u0131n\u0131 ekleyerek yapt\u0131ysa, Manage NuGets Packages ile kurunca hata d\u00fczeliyor.<\/p>\n<p style=\"text-align:justify;\">Yaz\u0131 boyunca anlat\u0131lan kod&#8217;un source dosyas\u0131 : <a title=\"Foursquare Web \u00d6rne\u011fi\" href=\"https:\/\/www.dropbox.com\/s\/9c15eotcomue5yk\/metehantoksoy.com.rar?m=\" target=\"_blank\">Dropbox &#8211; Metehan Toksoy<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Merhabalar. Uzunca bir aradan sonra blog yazmaya yeni f\u0131rsat buldum ve \u00f6\u011frendi\u011fim bir \u015feyi sizlerle payla\u015f\u0131yorum. Umar\u0131m yararl\u0131 olur. Bug\u00fcnk\u00fc konumuz C# .Net ile Foursquare API. \u00a0Windows Phone 8 geli\u015ftirdi\u011fim Sade Kahve uygulamama ne zamand\u0131r eklemek isteyip eklemeye vakit bulamad\u0131\u011f\u0131m en yak\u0131n kahve d\u00fckkan\u0131n\u0131 bulma \u00f6zelli\u011fini sonunda ekledim. Sizin konumunuzu al\u0131p, Bing Maps ile sizi, &hellip; <a href=\"https:\/\/metehantoksoy.com\/?p=764\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;C# ile Foursquare API Kullanarak Uygulama Geli\u015ftirme&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[14,2],"tags":[17,43,63,68,69,88,106,49,217,229,239,250,253,256,257,265,269],"class_list":["post-764","post","type-post","status-publish","format-standard","hentry","category-c","category-development","tag-net","tag-api","tag-c","tag-clientid","tag-clientsecret","tag-dev","tag-foursquare","tag-ornek-kod","tag-resimli-anlatim","tag-sharpsquare","tag-store","tag-venues","tag-visual-studio","tag-web-api","tag-windows","tag-windows-phone-8-1","tag-wp-8-1"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/metehantoksoy.com\/index.php?rest_route=\/wp\/v2\/posts\/764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/metehantoksoy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/metehantoksoy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/metehantoksoy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/metehantoksoy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=764"}],"version-history":[{"count":0,"href":"https:\/\/metehantoksoy.com\/index.php?rest_route=\/wp\/v2\/posts\/764\/revisions"}],"wp:attachment":[{"href":"https:\/\/metehantoksoy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/metehantoksoy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/metehantoksoy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}