Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1141 connectés 

  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [C#] Utilisation de Google Calendar

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[C#] Utilisation de Google Calendar

n°2184084
MagicBuzz
Posté le 04-04-2013 à 14:38:41  profilanswer
 

Bonjour,
 
J'essaie de faire une interface entre un outil de CRM et Google Calendar, afin de relater les rendez-vous pris dans le CRM directement sur les agendas des salariés de l'organisation Google Applications.
 
Je suis parti sur une application C# basée sur sur les API de Google Calendar.
 
Cependant, je ne m'en sors pas : j'ai réussi à lire mon propre calendrier, mais depuis 10 jours maintenant, je ne vois aucune modification que j'y ai apporté depuis : je charge toujours le calendrier tel qu'il était à l'époque.
 
Et quand je fais un modification sur un événement du calendrier, je ne vois pas la modification apparaître. Je n'ai pourtant aucune erreur.
 
Connaissez-vous un site qui propose un tuto ou des exemple d'implémentation de cette API ?
 
Sur le site de Google, il n'y a absolument aucun exemple (3 lignes de code pas fonctionnelles)

mood
Publicité
Posté le 04-04-2013 à 14:38:41  profilanswer
 

n°2187090
Je@nb
Kindly give dime
Posté le 23-04-2013 à 00:46:33  profilanswer
 

Hmmm, jamais fait mais j'avais un peu regardé.
 
Tu as un exemple de code ? Tu as pas ton proxy dans ta boite (si tu passes par un proxy) qui met en cache et t'empêche de renouvelle tes requêtes ?
 
Tu passes bien la clé de ton appli ?

n°2187162
MagicBuzz
Posté le 23-04-2013 à 12:24:15  profilanswer
 

Non, je ne passe pas par un proxy.

 

Voici mon code :

 

frmMain.cs

Code :
  1. using System;
  2. using System.Diagnostics;
  3. using System.Linq;
  4. using System.Windows.Forms;
  5.  
  6. using DotNetOpenAuth.OAuth2;
  7.  
  8. using Google.Apis.Authentication.OAuth2;
  9. using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
  10. using Google.Apis.Services;
  11. using Google.Apis.Util;
  12.  
  13. using Google.Apis.Calendar.v3;
  14. using Google.Apis.Calendar.v3.Data;
  15.  
  16. using GoogleCalendar;
  17.  
  18.  
  19. namespace TestGoogleCalendar
  20. {
  21.    public partial class frmMain : Form
  22.    {
  23.        private Google.Apis.Calendar.v3.CalendarService service;
  24.  
  25.        public frmMain()
  26.        {
  27.            InitializeComponent();
  28.            listView1.Sorting = SortOrder.Ascending;
  29.        }
  30.  
  31.        private void frmMain_Load(object sender, EventArgs e)
  32.        {
  33.            TestMethod1();
  34.        }
  35.  
  36.        private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
  37.        {
  38.            // Get the auth URL:
  39.            IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
  40.            state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
  41.            Uri authUri = arg.RequestUserAuthorization(state);
  42.  
  43.            // Request authorization from the user (by opening a browser window):
  44.            Process.Start(authUri.ToString());
  45.  
  46.            frmGetToken fToken = new frmGetToken();
  47.            fToken.ShowDialog();
  48.            string authCode = fToken.Token;
  49.  
  50.            // Retrieve the access token by using the authorization code:
  51.            return arg.ProcessUserAuthorization(authCode, state);
  52.        }
  53.  
  54.        public void TestMethod1()
  55.        {
  56.            var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description)
  57.            {
  58.                ClientIdentifier = "xxxx.apps.googleusercontent.com",
  59.                ClientSecret = "zzzzz"
  60.            };
  61.  
  62.            var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
  63.  
  64.            service = new Google.Apis.Calendar.v3.CalendarService(new BaseClientService.Initializer()
  65.            {
  66.                Authenticator = auth
  67.            });
  68.  
  69.            CalendarList cl = service.CalendarList.List().Fetch();
  70.            comboBox1.Items.Clear();
  71.            foreach (CalendarListEntry cle in cl.Items)
  72.            {
  73.                comboBox1.Items.Add(new CalendarEntry(cle));
  74.            }
  75.        }
  76.  
  77.        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  78.        {
  79.            LoadDay();
  80.        }
  81.  
  82.        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
  83.        {
  84.            LoadDay();
  85.        }
  86.  
  87.        private void dateTimePicker2_ValueChanged(object sender, EventArgs e)
  88.        {
  89.            LoadDay();
  90.        }
  91.  
  92.        private void LoadDay()
  93.        {
  94.            listView1.Items.Clear();
  95.  
  96.            if (comboBox1.SelectedItem == null) return;
  97.  
  98.            EventsResource.ListRequest lr = service.Events.List((comboBox1.SelectedItem as CalendarEntry).Id);
  99.            Events e = lr.Fetch();
  100.            foreach (Event s in e.Items)
  101.            {
  102.                if (s.Status == "cancelled" ) continue;
  103.                string a = (s.Start.DateTime != null) ? s.Start.DateTime : s.Start.Date;
  104.                DateTime dt = DateTime.Parse(a);
  105.                if (dt >= dateTimePicker1.Value.Date && dt < dateTimePicker2.Value.AddDays(1).Date)
  106.                {
  107.                    ListViewItem i = new ListViewItem(new []{dt.ToString(), s.Summary});
  108.                    i.Tag = s;
  109.                    listView1.Items.Add(i);
  110.                }
  111.            }
  112.        }
  113.  
  114.        private void listView1_DoubleClick(object sender, EventArgs e)
  115.        {
  116.            if (listView1.SelectedItems[0].Tag != null)
  117.            {
  118.                frmCalendarEntry entry = new frmCalendarEntry(listView1.SelectedItems[0].Tag as Event);
  119.                entry.ShowDialog();
  120.                service.Events.Update(entry.evt, (comboBox1.SelectedItem as CalendarEntry).Id, entry.evt.Id);
  121.                LoadDay();
  122.            }
  123.        }
  124.    }
  125. }
 

Quand je lance, ça m'ouvre une page dans Chrome, me demandant de m'identifier avec mon compte Google.
Je récupère ensuite un code que je copie/colle et que je récupère avec ce code :

Code :
  1. frmGetToken fToken = new frmGetToken();
  2.            fToken.ShowDialog();
  3.            string authCode = fToken.Token;
 

Evidement, ClientIdentifier et ClientSecret sont remplis correctement avec les informations trouvées dans mon compte Google Apps.


Message édité par MagicBuzz le 23-04-2013 à 12:25:11

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [C#] Utilisation de Google Calendar

 

Sujets relatifs
Créer un dossier avec la date sous forme jj-mm-aaaa avec C#Connexion a un site avec compte Google ou Facebook
[C] A l'aide je ne comprends rien a ce programme[C] Remplacer un char dans une chaine de caractère
langage C - PB unsigned charlangage C
C++ - Cplex problem de variable dans une boucle for & random[Objective C][Cocoa] Détecter si un host est accessible
[C#] Trier un tableau d'objet 
Plus de sujets relatifs à : [C#] Utilisation de Google Calendar


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR