Merhaba arkadaslar
Internette gunlerdir ariyorum ancak guncel calisan Class bulamadim. Elinde Analytics'den c#, asp.net ile istatistik alabilecegim bir Class olan var mi?
Tesekkurler
Google Analytics'den Istatistik Almak (C#)
3
●1.929
- 10-09-2014, 22:21:14Kimlik doğrulama veya yönetimden onay bekliyor.Class'ı kendin yazabilirsin.
Analytics api'leri nasıl yapabileceğini adım adım gösteriyor.
https://developers.google.com/oauthplayground/ - 19-09-2014, 09:33:02burda çok genel bilgiler var, burdan analytics ile bağlantıyı nasıl kurup bilgileri çekebilirim?rob33n adlı üyeden alıntı: mesajı görüntüle
- 19-09-2014, 13:32:59Nasıl çok genel bilgiler? Aradığın tüm bilgiler orada. Nasıl giriş yapacağını, nasıl yetki alacağını ve yetkileri aldıktan sonra nasıl verileri çekeceğini gösteriyor. Restsharp kullanarak çok basit şekilde yapabilirsin.
Bak bu aşağıdaki kod parçasını google kişileri kendi sistemime import etmek için yazmıştım.
private string clientId = ConfigurationManager.AppSettings["GoogleClientId"]; private string clientSecret = ConfigurationManager.AppSettings["GoogleSecretKey"]; private string returnUri = ConfigurationManager.AppSettings["GoogleReturnUri"]; // GET: Google public ActionResult Index() { var clientAuth = new RestClient(); clientAuth.BaseUrl = "https://accounts.google.com/o/oauth2/auth"; var request = new RestRequest(Method.GET); request.RequestFormat = DataFormat.Json; request.AddParameter("scope", "https://www.google.com/m8/feeds/"); request.AddParameter("redirect_uri", returnUri); request.AddParameter("response_type", "code"); request.AddParameter("client_id", clientId); request.AddParameter("approval_prompt", "force"); var response = clientAuth.Execute(request); Response.Redirect(response.ResponseUri.ToString()); return View(); } public async Task<ActionResult> GetContacts() { List<Contacts> contactlist = new List<Contacts>(); var code = Request.QueryString["code"]; if (code != null) { var client = new RestClient(); client.BaseUrl = "https://accounts.google.com/o/oauth2/token"; var request = new RestRequest(Method.POST); request.AddParameter("code", code); request.AddParameter("redirect_uri", returnUri); request.AddParameter("client_id", clientId); request.AddParameter("scope", "https://www.google.com/m8/feeds/"); request.AddParameter("client_secret", clientSecret); request.AddParameter("grant_type", "authorization_code"); // most important part !!!! -------------------------- //.ContentType = "application/x-www-urlencoded"; var response = client.Execute(request); response.ContentType = "application/x-www-urlencoded"; if (response.StatusCode == System.Net.HttpStatusCode.OK) { var content = JsonConvert.DeserializeObject<Token>(response.Content); var access_token = content.access_token; var token_type = content.token_type; var expires_in = content.expires_in; var refresh_token = content.refresh_token; var contactClient = new RestClient(); contactClient.BaseUrl = "https://www.google.com/m8/feeds/contacts/default/full"; var contactRequest = new RestRequest(Method.GET); contactRequest.RequestFormat = DataFormat.Json; contactRequest.AddParameter("max-results", "9999"); contactRequest.AddParameter("sortorder", "ascending"); contactRequest.AddParameter("alt", "json"); contactRequest.AddParameter("access_token", access_token); contactRequest.AddParameter("access_token_type", token_type); var contactResponse = contactClient.Execute(contactRequest); contactResponse.ContentType = "application/json"; if (contactResponse.StatusCode == System.Net.HttpStatusCode.OK) { var json = contactResponse.Content; JObject o = JObject.Parse(json); //JsonConvert.DeserializeObject(o.SelectToken("$..entry"), (new JToken()).GetType()); foreach (var result in o.SelectToken("$..entry")) { Dictionary<string, string> emails = new Dictionary<string, string>(); Dictionary<string, string> phones = new Dictionary<string, string>(); var name = result["title"]["$t"].ToString(); var em = result["gd$email"]; var pn = result["gd$phoneNumber"]; var org = result["gd$organization"]; var note = result["gd$content"]; var workTitle = string.Empty; var company = string.Empty; try { // get emails if (em != null && em.Any()) { if (em.Children().First()["rel"].ToString().Contains("#home")) emails.Add("home", em.Children().First()["address"].ToString()); if (em.Children().First()["rel"].ToString().Contains("#work")) emails.Add("work", em.Children().First()["address"].ToString()); if (em.Children().First()["rel"].ToString().Contains("#other")) emails.Add("other", em.Children().First()["address"].ToString()); } // get phone numbers if (pn != null && pn.Any()) { if (pn.Children().First()["rel"].ToString().Contains("#home")) phones.Add("home", pn.Children().First()["$t"].ToString()); if (pn.Children().First()["rel"].ToString().Contains("#mobile")) phones.Add("mobile", pn.Children().First()["$t"].ToString()); if (pn.Children().First()["rel"].ToString().Contains("#work")) phones.Add("work", pn.Children().First()["$t"].ToString()); } // get organization details if (org != null && org.Any()) { workTitle = org.Children().First()["gd$orgTitle"] != null ? org.Children().First()["gd$orgTitle"]["$t"].ToString() : ""; company = org.Children().First()["gd$orgName"] != null ? org.Children().First()["gd$orgName"]["$t"].ToString() : null; } // get note if (note != null && note.Any()) { note = note["$t"].ToString(); } if (string.IsNullOrEmpty(name)) { if (emails.Count > 0) foreach (var item in emails) { name = item.Value; } else if (!string.IsNullOrEmpty(company)) name = company; else name = null; } } catch (Exception ex) { string error = ex.Message; throw; } var contact = new Contacts(); contact.LastName = name; foreach (var item in emails) { if (item.Key == "home") contact.EmailAddress = item.Value; if (item.Key == "work") contact.EmailAddress2 = item.Value; if (item.Key == "other") contact.EmailAddress2 = item.Value; } foreach (var item in phones) { if (item.Key == "home") contact.PhoneHome = item.Value; if (item.Key == "work") contact.Phone = item.Value; if (item.Key == "mobile") contact.Mobile = item.Value; } contact.Description = note != null ? note.ToString() : ""; contact.JobTitle = workTitle != null ? workTitle : ""; contactlist.Add(contact); } } } } return View(contactlist); }