예제 #1
0
        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;
                }
            }
        }
예제 #2
0
        public GoogleDocs GetGoogleDocs()
        {
            if (m_token.IsExpired())
                m_token = RefreshToken(m_token);

            GoogleDocs docs = new GoogleDocs(m_token, m_email);
            return docs;
        }
예제 #3
0
 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();
     }
 }
예제 #4
0
 public GoogleDocs(GoogleOAuthSession token, string email)
 {
     m_token = token;
     m_email = email;
     m_request = new DocumentsRequest(new RequestSettings(MvcApplication.APPNAME, m_token.access_token));
 }