Ejemplo n.º 1
0
        static void Drivev3()
        {
            Token = GoogleDrive.GetToken(email_gd);
            DriveAPIv3 v3   = new DriveAPIv3(Token);
            string     data = v3.About_Get();

            Console.WriteLine(data);
        }
Ejemplo n.º 2
0
        public static void Gdclient_TokenRenewEvent(TokenGoogleDrive token)
        {
            XmlNode cloud = AppSetting.settings.GetCloud(token.Email, CloudType.GoogleDrive);

            if (cloud != null)
            {
                AppSetting.settings.ChangeToken(cloud, JsonConvert.SerializeObject(token));
            }
            else
            {
                throw new Exception("Can't save token.");
            }
        }
Ejemplo n.º 3
0
        internal static TokenGoogleDrive GetToken(string Email)
        {
            foreach (TokenGoogleDrive token in Tokens)
            {
                if (token.Email == Email)
                {
                    return(token);
                }
            }
            TokenGoogleDrive tk = JsonConvert.DeserializeObject <TokenGoogleDrive>(AppSetting.settings.GetToken(Email, CloudType.GoogleDrive));

            Tokens.Add(tk);
            tk.EventTokenUpdate += Tk_EventTokenUpdate;
            return(tk);
        }
Ejemplo n.º 4
0
 private void Oauth_gd_TokenCallBack(string token_)
 {
     if (!string.IsNullOrEmpty(token_))
     {
         TokenGoogleDrive token = JsonConvert.DeserializeObject <TokenGoogleDrive>(token_);
         if (token.IsError)
         {
             throw new Exception("Accesstoken:" + token.access_token + ",RefreshToken:" + token.refresh_token);
         }
         string        token_text = JsonConvert.SerializeObject(token);
         DriveAPIv2    client     = new DriveAPIv2(token);
         Drivev2_About about      = client.About.Get();
         SaveToken(about.user.emailAddress, token_text, CloudType.GoogleDrive);
     }
     else
     {
         throw new Exception("Oauth token GD failed.");
     }
 }
Ejemplo n.º 5
0
        public TokenGoogleDrive RefreshToken()
        {
            if (string.IsNullOrEmpty(token.refresh_token))
            {
                throw new Exception("refresh_token can't be null");
            }
            string tokenRequestBody = string.Format("client_id={0}&client_secret={1}&refresh_token={2}&grant_type=refresh_token",
                                                    GoogleDriveAppKey.ClientID, GoogleDriveAppKey.Clientsecret, token.refresh_token);
            HttpWebRequest tokenRequest = (HttpWebRequest)WebRequest.Create(tokenEndpoint);

            tokenRequest.Method      = "POST";
            tokenRequest.ContentType = "application/x-www-form-urlencoded";
            tokenRequest.Accept      = "Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            byte[] _byteVersion = Encoding.ASCII.GetBytes(tokenRequestBody);
            tokenRequest.ContentLength = _byteVersion.Length;
            using (Stream stream = tokenRequest.GetRequestStream())
            {
                stream.Write(_byteVersion, 0, _byteVersion.Length);
                stream.Flush();
            }
            try
            {
                WebResponse tokenResponse = tokenRequest.GetResponse();
                using (StreamReader reader = new StreamReader(tokenResponse.GetResponseStream()))
                {
                    TokenGoogleDrive new_token = JsonConvert.DeserializeObject <TokenGoogleDrive>(reader.ReadToEnd());
                    token.access_token = new_token.access_token;
                    token.expires_in   = new_token.expires_in;
                    token.id_token     = new_token.id_token;
                    return(token);
                }
            }
            catch (Exception ex)
            {
                this.Error_refresh_token = ex.Message;
                return(null);
            }
        }
Ejemplo n.º 6
0
 public GoogleAPIOauth2(TokenGoogleDrive token)
 {
     this.token = token;
 }
Ejemplo n.º 7
0
 private static void TokenRenewEvent(TokenGoogleDrive token)
 {
     Token = token;
     AppSetting.settings.ChangeToken(AppSetting.settings.GetCloud(token.Email, CloudType.GoogleDrive), JsonConvert.SerializeObject(token));
 }