// // PeopleApi.cs // // Author: // Paul Schneider // // Copyright (c) 2015 GNU GPL // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . using System.IO; using System.Net; using Newtonsoft.Json; using Yavsc.Abstract.Identity; using Yavsc.Models.Google; namespace Yavsc.GoogleApis { /// /// Google People API. /// public class PeopleApi { /// /// The get people URI. /// protected static string getPeopleUri = "https://www.googleapis.com/plus/v1/people"; /// /// Initializes a new instance of the class. /// /// Auth type. /// Redirect URI. public PeopleApi() { } /// /// Gets the People object associated to the given Google Access Token /// /// The me. /// The Google Access Token object class. public People GetMe(AuthToken gat) { People me; HttpWebRequest webreppro = WebRequest.CreateHttp(getPeopleUri + "/me"); webreppro.ContentType = "application/http"; webreppro.Headers.Add(HttpRequestHeader.Authorization, gat.token_type + " " + gat.access_token); webreppro.Method = "GET"; using (WebResponse proresp = webreppro.GetResponse()) { using (Stream prresponseStream = proresp.GetResponseStream()) { using (StreamReader rdr = new StreamReader(prresponseStream)) { me = JsonConvert.DeserializeObject(rdr.ReadToEnd()); prresponseStream.Close(); } proresp.Close(); } webreppro.Abort(); return me; } } } }