{"id":1915,"date":"2010-12-12T02:00:12","date_gmt":"2010-12-12T01:00:12","guid":{"rendered":"http:\/\/blogs.wittwer.fr\/whiler\/?p=1915"},"modified":"2012-03-03T04:12:43","modified_gmt":"2012-03-03T03:12:43","slug":"delphi-google-contacts","status":"publish","type":"post","link":"https:\/\/blogs.wittwer.fr\/whiler\/2010\/12\/12\/delphi-google-contacts\/","title":{"rendered":"R\u00e9cup\u00e9rer ses contacts Google avec Delphi"},"content":{"rendered":"<p>Afin de d\u00e9boguer une application <a href=\"http:\/\/fr.wikipedia.org\/wiki\/Android\" rel=\"glossary\" target=\"_blank\" title=\"Wikipedia, D&eacute;finition de&nbsp;: Android\" style=\"\" >Android<\/a><sup style=\"font-family: Georgia, Times New Roman, Serif; font-weight: bold; color: #AAAAAA\" ><em>W<\/em><\/sup>, je me suis rapidement cr\u00e9er une application en <a href=\"http:\/\/fr.wikipedia.org\/wiki\/Delphi_(informatique)\" rel=\"glossary\" target=\"_blank\" title=\"Wikipedia, D&eacute;finition de&nbsp;: Delphi\" style=\"\" >Delphi<\/a><sup style=\"font-family: Georgia, Times New Roman, Serif; font-weight: bold; color: #AAAAAA\" ><em>W<\/em><\/sup> pour r\u00e9cup\u00e9rer mes contacts Google au format <a href=\"http:\/\/fr.wikipedia.org\/wiki\/XML\" rel=\"glossary\" target=\"_blank\" title=\"Wikipedia, D&eacute;finition de&nbsp;: XML\" style=\"\" >XML<\/a><sup style=\"font-family: Georgia, Times New Roman, Serif; font-weight: bold; color: #AAAAAA\" ><em>W<\/em><\/sup>&#8230;<\/p>\n<p>La m\u00e9thode est relativement simple et expliqu\u00e9e sur cette page&nbsp;: <a target=\"_blank\" href=\"https:\/\/code.google.com\/intl\/fr\/apis\/contacts\/docs\/2.0\/developers_guide_protocol.html#Retrieving\">Developer&rsquo;s Guide: Protocol &#8211; Google Contacts Data API &#8211; Google Code<\/a><\/p>\n<p>Pour cela, j&rsquo;ai cr\u00e9\u00e9 une nouvelle application Fiche <a href=\"http:\/\/fr.wikipedia.org\/wiki\/VCL\" rel=\"glossary\" target=\"_blank\" title=\"Wikipedia, D&eacute;finition de&nbsp;: VCL\" style=\"\" >VCL<\/a><sup style=\"font-family: Georgia, Times New Roman, Serif; font-weight: bold; color: #AAAAAA\" ><em>W<\/em><\/sup>, sur laquelle j&rsquo;ai ajout\u00e9&nbsp;:<\/p>\n<ul>\n<li><strong>1 TMemo<\/strong>&nbsp;: pour afficher le XML<\/li>\n<li><strong>4 TLabeledEdit<\/strong>&nbsp;: pour saisir les informations n\u00e9cessaires \u00e0 l&rsquo;authentification<\/li>\n<li><strong>1 TButton<\/strong>&nbsp;: pour ex\u00e9cuter la r\u00e9cup\u00e9ration des informations<\/li>\n<li><strong>1 TIdHTTP<\/strong>&nbsp;: pour me connecter au site de Google<\/li>\n<li><strong>1 TIdSSLIOHandlerSocketOpenSSL<\/strong>&nbsp;: pour supporter le protocole SSL (utilis\u00e9 par Google)<\/li>\n<\/ul>\n<p>J&rsquo;ai sp\u00e9cifi\u00e9 que le <em>TIdHTTP<\/em> utilise le <em>TIdSSLIOHandlerSocketOpenSSL<\/em> comme <em>IOHandler<\/em>.<\/p>\n<p>Puis j&rsquo;ai double-cliqu\u00e9 sur le bouton pour g\u00e9n\u00e9rer sa m\u00e9thode <em>Click<\/em> dans laquelle j&rsquo;ai utilis\u00e9 le code suivant&nbsp;:<br \/>\n<!--more--><\/p>\n<div class=\"codecolorer-container delphi dawn\" style=\"overflow:auto;white-space:nowrap;width:480px;height:300px;\"><table cellspacing=\"0\" cellpadding=\"0\"><tbody><tr><td class=\"line-numbers\"><div>1<br \/>2<br \/>3<br \/>4<br \/>5<br \/>6<br \/>7<br \/>8<br \/>9<br \/>10<br \/>11<br \/>12<br \/>13<br \/>14<br \/>15<br \/>16<br \/>17<br \/>18<br \/>19<br \/>20<br \/>21<br \/>22<br \/>23<br \/>24<br \/>25<br \/>26<br \/>27<br \/>28<br \/>29<br \/>30<br \/>31<br \/>32<br \/>33<br \/>34<br \/>35<br \/>36<br \/>37<br \/><\/div><\/td><td><div class=\"delphi codecolorer\"><span class=\"kw1\">procedure<\/span> TForm2<span class=\"sy1\">.<\/span><span class=\"me1\">btnGetContactsClick<\/span><span class=\"br0\">&#40;<\/span>Sender<span class=\"sy1\">:<\/span> <span class=\"kw4\">TObject<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy1\">;<\/span><br \/>\n&nbsp;<span class=\"kw1\">var<\/span><br \/>\n&nbsp; slParams <span class=\"sy1\">:<\/span> TStringList<span class=\"sy1\">;<\/span><br \/>\n&nbsp; sSID &nbsp; &nbsp; <span class=\"sy1\">:<\/span> <span class=\"kw4\">string<\/span><span class=\"sy1\">;<\/span><br \/>\n&nbsp; sContacts<span class=\"sy1\">:<\/span> <span class=\"kw4\">string<\/span><span class=\"sy1\">;<\/span><br \/>\n<span class=\"kw1\">begin<\/span><br \/>\n&nbsp; Screen<span class=\"sy1\">.<\/span><span class=\"me1\">Cursor<\/span> <span class=\"sy1\">:<\/span><span class=\"sy3\">=<\/span> crHourGlass<span class=\"sy1\">;<\/span><br \/>\n&nbsp; slParams <span class=\"sy1\">:<\/span><span class=\"sy3\">=<\/span> TStringList<span class=\"sy1\">.<\/span><span class=\"me1\">Create<\/span><span class=\"sy1\">;<\/span><br \/>\n&nbsp; <span class=\"kw1\">try<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Purge des pr\u00e9c\u00e9dents headers<\/span><br \/>\n&nbsp; &nbsp; idhtpGoogle<span class=\"sy1\">.<\/span><span class=\"me1\">Request<\/span><span class=\"sy1\">.<\/span><span class=\"me1\">CustomHeaders<\/span><span class=\"sy1\">.<\/span><span class=\"me1\">Clear<\/span><span class=\"sy1\">;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; slParams<span class=\"sy1\">.<\/span><span class=\"me1\">Add<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'accountType=GOOGLE'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy1\">;<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class=\"co1\">\/\/ Type de compte<\/span><br \/>\n&nbsp; &nbsp; slParams<span class=\"sy1\">.<\/span><span class=\"me1\">Add<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'Email='<\/span> &nbsp; <span class=\"sy3\">+<\/span> lbledtEmail<span class=\"sy1\">.<\/span><span class=\"me1\">Text<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy1\">;<\/span> &nbsp; &nbsp; <span class=\"co1\">\/\/ email du compte<\/span><br \/>\n&nbsp; &nbsp; slParams<span class=\"sy1\">.<\/span><span class=\"me1\">Add<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'Passwd='<\/span> &nbsp;<span class=\"sy3\">+<\/span> lbledtPassword<span class=\"sy1\">.<\/span><span class=\"me1\">Text<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy1\">;<\/span> &nbsp;<span class=\"co1\">\/\/ mot de passe du compte<\/span><br \/>\n&nbsp; &nbsp; slParams<span class=\"sy1\">.<\/span><span class=\"me1\">Add<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'service='<\/span> <span class=\"sy3\">+<\/span> lbledtService<span class=\"sy1\">.<\/span><span class=\"me1\">Text<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy1\">;<\/span> &nbsp; <span class=\"co1\">\/\/ cp<\/span><br \/>\n&nbsp; &nbsp; slParams<span class=\"sy1\">.<\/span><span class=\"me1\">Add<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'source='<\/span> &nbsp;<span class=\"sy3\">+<\/span> lbledtSource<span class=\"sy1\">.<\/span><span class=\"me1\">Text<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy1\">;<\/span> &nbsp; &nbsp;<span class=\"co1\">\/\/ une cha\u00eene au format companyName-applicationName-versionID<\/span><br \/>\n&nbsp; &nbsp; idhtpGoogle<span class=\"sy1\">.<\/span><span class=\"me1\">Request<\/span><span class=\"sy1\">.<\/span><span class=\"me1\">ContentType<\/span> <span class=\"sy1\">:<\/span><span class=\"sy3\">=<\/span> <span class=\"st0\">'application\/x-www-form-urlencoded'<\/span><span class=\"sy1\">;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ R\u00e9cup\u00e9ration de la cl\u00e9 d'authentification<\/span><br \/>\n&nbsp; &nbsp; slParams<span class=\"sy1\">.<\/span><span class=\"me1\">DelimitedText<\/span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class=\"sy1\">:<\/span><span class=\"sy3\">=<\/span> idhtpGoogle<span class=\"sy1\">.<\/span><span class=\"me1\">Post<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'https:\/\/www.google.com\/accounts\/ClientLogin'<\/span><span class=\"sy1\">,<\/span>slParams<span class=\"br0\">&#41;<\/span><span class=\"sy1\">;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Passage de la cl\u00e9<\/span><br \/>\n&nbsp; &nbsp; idhtpGoogle<span class=\"sy1\">.<\/span><span class=\"me1\">Request<\/span><span class=\"sy1\">.<\/span><span class=\"me1\">CustomHeaders<\/span><span class=\"sy1\">.<\/span><span class=\"me1\">Add<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'Authorization:GoogleLogin auth='<\/span> <span class=\"sy3\">+<\/span> slParams<span class=\"sy1\">.<\/span><span class=\"me1\">Values<\/span><span class=\"br0\">&#91;<\/span><span class=\"st0\">'Auth'<\/span><span class=\"br0\">&#93;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy1\">;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ Every request that you send using the Contacts Data API should specify version 3.0 of the API.<\/span><br \/>\n&nbsp; &nbsp; idhtpGoogle<span class=\"sy1\">.<\/span><span class=\"me1\">Request<\/span><span class=\"sy1\">.<\/span><span class=\"me1\">CustomHeaders<\/span><span class=\"sy1\">.<\/span><span class=\"me1\">Add<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'GData-Version: 3.0'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy1\">;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ On demande les 500 premiers contacts<\/span><br \/>\n&nbsp; &nbsp; sContacts <span class=\"sy1\">:<\/span><span class=\"sy3\">=<\/span> idhtpGoogle<span class=\"sy1\">.<\/span><span class=\"me1\">get<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">'https:\/\/www.google.com\/m8\/feeds\/contacts\/default\/full?max-results=500'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy1\">;<\/span><br \/>\n<br \/>\n&nbsp; &nbsp; <span class=\"co1\">\/\/ On affiche les contacts en formatant le XML (uses XMLDoc)<\/span><br \/>\n&nbsp; &nbsp; mmo1<span class=\"sy1\">.<\/span><span class=\"me1\">Text<\/span> <span class=\"sy1\">:<\/span><span class=\"sy3\">=<\/span> xmlDoc<span class=\"sy1\">.<\/span><span class=\"me1\">FormatXMLData<\/span><span class=\"br0\">&#40;<\/span>sContacts<span class=\"br0\">&#41;<\/span><span class=\"sy1\">;<\/span><br \/>\n&nbsp; <span class=\"kw1\">finally<\/span><br \/>\n&nbsp; &nbsp; slParams<span class=\"sy1\">.<\/span><span class=\"me1\">free<\/span><span class=\"sy1\">;<\/span><br \/>\n&nbsp; &nbsp; Screen<span class=\"sy1\">.<\/span><span class=\"me1\">Cursor<\/span> <span class=\"sy1\">:<\/span><span class=\"sy3\">=<\/span> crDefault<span class=\"sy1\">;<\/span><br \/>\n&nbsp; <span class=\"kw1\">end<\/span><span class=\"sy1\">;<\/span><br \/>\n<span class=\"kw1\">end<\/span><span class=\"sy1\">;<\/span><\/div><\/td><\/tr><\/tbody><\/table><\/div>\n<p>Normalement, vous devriez ainsi avoir vos diff\u00e9rents contacts et leurs informations associ\u00e9es. Il n&rsquo;y a pas photo, Delphi est un environnement <a href=\"http:\/\/fr.wikipedia.org\/wiki\/D\u00e9veloppement_rapide_d&rsquo;applications\" rel=\"glossary\" target=\"_blank\" title=\"Wikipedia, D&eacute;finition de&nbsp;: RAD\" style=\"\" >RAD<\/a><sup style=\"font-family: Georgia, Times New Roman, Serif; font-weight: bold; color: #AAAAAA\" ><em>W<\/em><\/sup> <img src=\"https:\/\/blogs.wittwer.fr\/whiler\/wp-includes\/images\/smilies\/skype\/\/happy.gif\" alt=\"(lol)\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <\/p>\n<p>Sur le m\u00eame principe, vous pouvez \u00e9galement attaqu\u00e9 l&rsquo;agenda, le Reader, &#8230;, de Google, maintenant que vous avez votre cl\u00e9 d&rsquo;autorisation.<\/p>\n<div class=\"thanks_button_div\" \n                  style=\"float: right; margin-right: 10px; margin-top:10px;\"><div id=\"thanksButtonDiv_1915_1\" style=\"background-image:url(https:\/\/blogs.wittwer.fr\/whiler\/wp-content\/plugins\/thanks-you-counter-button\/images\/thanks_compact_brown1.png); background-repeat:no-repeat; float: left; display: inline;\"\n                onmouseover=\"javascript:thankYouChangeButtonImage('thanksButtonDiv_1915_1', true);\" \n                onmouseout=\"javascript:thankYouChangeButtonImage('thanksButtonDiv_1915_1', false);\"\n                onclick=\"javascript:thankYouChangeButtonImage('thanksButtonDiv_1915_1', false);\" >\n                <input type=\"button\" onclick=\"thankYouButtonClick(1915, 'You left &ldquo;Thanks&rdquo; already for this post')\" value=\"Merci\u00a0 7\"\n                  class=\"thanks_button thanks_compact thanks_brown1\"\n                  style=\"  font-family: Verdana, Arial, Sans-Serif; font-size: 14px; font-weight: normal;; color:#00f;\"\n                  id=\"thanksButton_1915_1\" title=\"Click to leave &ldquo;Thanks&rdquo; for this post\"\/>\n             <\/div><div id=\"ajax_loader_1915_1\" style=\"display:inline;visibility: hidden;\"><img decoding=\"async\" alt=\"ajax loader\" src=\"https:\/\/blogs.wittwer.fr\/whiler\/wp-content\/plugins\/thanks-you-counter-button\/images\/ajax-loader.gif\" \/><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Afin de d\u00e9boguer une application Android, je me suis rapidement cr\u00e9er une application en Delphi pour r\u00e9cup\u00e9rer mes contacts Google au format XML\u2026<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[7,6],"tags":[158,15,27,154,43,157,108],"class_list":["post-1915","post","type-post","status-publish","format-standard","hentry","category-delphi","category-dev","tag-android","tag-api","tag-coloration-syntaxique","tag-delphi","tag-donnees","tag-google","tag-script"],"_links":{"self":[{"href":"https:\/\/blogs.wittwer.fr\/whiler\/wp-json\/wp\/v2\/posts\/1915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.wittwer.fr\/whiler\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.wittwer.fr\/whiler\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.wittwer.fr\/whiler\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.wittwer.fr\/whiler\/wp-json\/wp\/v2\/comments?post=1915"}],"version-history":[{"count":0,"href":"https:\/\/blogs.wittwer.fr\/whiler\/wp-json\/wp\/v2\/posts\/1915\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.wittwer.fr\/whiler\/wp-json\/wp\/v2\/media?parent=1915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.wittwer.fr\/whiler\/wp-json\/wp\/v2\/categories?post=1915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.wittwer.fr\/whiler\/wp-json\/wp\/v2\/tags?post=1915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}