public GoogleDocsRepository(string code) { m_token = GetSessionToken(code); if (string.IsNullOrEmpty(m_email)) { using (MiniProfiler.Current.Step("Get gmail address")) { DocumentsRequest request = new DocumentsRequest(new RequestSettings(MvcApplication.APPNAME, m_token.access_token)); m_email = request.GetFolders().AtomFeed.Authors[0].Email; } } }
public GoogleDocs GetGoogleDocs() { if (m_token.IsExpired()) m_token = RefreshToken(m_token); GoogleDocs docs = new GoogleDocs(m_token, m_email); return docs; }
private static GoogleOAuthSession RefreshToken(GoogleOAuthSession code) { using (MiniProfiler.Current.Step("GoogleDocsRepository.RefreshToken")) { return "https://accounts.google.com/o/oauth2/token" .Post(string.Format("client_id={1}&client_secret={2}&refresh_token={0}&grant_type=refresh_token" , System.Web.HttpUtility.UrlEncode(code.refresh_token) , System.Web.HttpUtility.UrlEncode(clientid) , System.Web.HttpUtility.UrlEncode(clientsecret))) .ExtractToken(); } }
public GoogleDocs(GoogleOAuthSession token, string email) { m_token = token; m_email = email; m_request = new DocumentsRequest(new RequestSettings(MvcApplication.APPNAME, m_token.access_token)); }