testtestHome

Récupérer son OPML Google Reader via PHP et CURL…

29.03.2009 par Mich - lees dit in het Nederlands - read this in English

Je n’aime pas faire du travail en double. Ainsi par exemple, lorsque je m’abonne à un blog car je le trouve intéressant, j’aimerais pouvoir l’afficher aussi dans ma blogroll. La solution s’appelle OPML.

Mon idée : récupérer de façon quotidienne mon fichier OPML de Google Reader et le stocker dans un répertoire sur mon serveur. La blogroll serait générée depuis ce fichier à chaque fois que quelqu’un aille la consulter. Et ainsi, à 24h près, elle serait toujours à jour.

Mais voila. La grosse merde, le gros bordel, le retour sur terre, c’est le suivant : pour accéder à votre fichier OPML il faut être authentifié et les choses un peu plus complèxe, car j’ai du essayer quelque chose que je n’avais jamais fait avant : utiliser cURL avec des cookies.

Le principe est simple : remplir les paramètres du formulaire de connexion Google avec CURL et stocker ce que celui-ci renvoie pour la cookie dans un fichier. Ensuite, réutiliser ce fichier comme cookie lorsque je veux accéder à l’URL de mon fichier OPML.

Si vous avez Google Reader, l’URL de votre fichier OPML est le suivant :

http://www.google.com/reader/public/subscriptions/user/<user_id>/

Vous pouvez obtenir votre userid en cliquant sur « All Items » ou « Tous mes éléments », un URL apparaîtra ensuite, votre user id est le numéro se trouvant entre les %2F, donc dans mon cas ‘06937166373900766291’:

http://www.google.com/reader/view/#stream/user%2F06937166373900766291%2Fstate%2Fcom.google%2Freading-list

Et voici donc le petit script PHP pour me connecter et récupérer le fichier OPML. Attention, j’utilise ici des noms de fichier absolu pour la cookie et le fichier final, la raison est simple : c’est parce que je compte également faire appel à ce script via un job crontab :

<?
$email="barney.stinson@gmail.com";
$password="br0";

$url = "https://www.google.com/accounts/ServiceLoginAuth?service=reader";
$params = "service=reader";
$params.= "&Email=".urlencode($email);
$params.= "&Passwd=$password";
$params.= "&continue=http://www.google.com/reader/";
$params.= "&hl=en";
$params.= "&nui=1";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookie.txt');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);

$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, "http://www.google.com/reader/public/subscriptions/user/06937166373900766291/");
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_COOKIEJAR, '/tmp/cookie.txt');
curl_setopt($ch2, CURLOPT_COOKIEFILE, '/tmp/cookie.txt');
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch2);
curl_close($ch2);

$fp = fopen("/home/emich.be/public_html/misc/google-reader-subscriptions.xml","w");
fputs($fp,$data);
fclose($fp);
unlink("/tmp/cookie.txt");
?>

Remplacez évidemment le login, mot de passe et user id par les vôtres. J'ai choisi de mettre ma cookie dans le dossier /tmp, afin qu'il ne soit pas visible depuis l'exterieur.

A noter que ce script peut également être écrit en bash script en utilisant directement cURL. J’ai opté pour l’option php car pas tout le monde a un serveur avec accès en ligne de commande à disposition.

tags: . . |
[... old blogs and new, and here are some new ...]
[...]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[...]…
[...]here are some links to sites that we link to because we think they are worth visiting[...]…
greco guitar - greco guitar (01/11/2011 @ 11:21)
The one stop shop website regarding auctions around The japanese. You can get Nippon online auctions and also have these items sent to your own house.
credit debt - Cool sites (01/12/2011 @ 18:38)
[...]we came across a cool site that you might enjoy. Take a look if you want[...]…
[...]below you’ll find the link to some sites that we think you should visit[...]…
[...]The information mentioned in the article are some of the best available [...]...
[...]here are some sites that we think it will cool you down[...]
That blog post was so excellent. I hereby award you the Blogging Silver Star 2011.
[...]here are some links to sites that we link to because we think they are worth visiting[...]…
[...]Sites of interest we have a link to[...]…
Gas chain saws - Websites (03/12/2011 @ 00:23)
[...]%BLOGTITLE%[...]
[...]just underneath, are a list of totally unrelated sites to ours, however, they are definitely worth checking out[...]
website design - hosting (07/12/2011 @ 15:50)
[...]the time to read or visit the content or sites we have linked to below the[...]
[...]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[...]…
brian ofsie - Sites we Like… (08/12/2011 @ 10:07)
[...] Every once in a while we choose blogs that we read. Listed below are the latest sites that we choose [...]…
nyc night clubs - Cool sites (08/12/2011 @ 11:39)
[...]we came across a cool site that you might enjoy. Take a look if you want[...]…
[...]the time to read or visit the content or sites we have linked to below the[...]…
reverse mortgage leads - Links (08/12/2011 @ 11:47)
[...]Sites of interest we have a link to[...]…
[...]while the sites we link to below are completely unrelated to ours, we think they are worth a read, so have a look[...]
[...]visiting we have linked to above[...]
[...]just below, are some totally interesting pages[...]
[...]while the places we link to underneath are completely unrelated to ours, we think they are worth a look, so have a look[...]
[...]Neat websites we got to[...]
brian ofsie - Sources (09/12/2011 @ 04:23)
[...]check below, are some totally unrelated websites to ours, however, they are most trustworthy sources that we use[...]…
[...]Here are some of the sites we recommend for our visitors[...]…
[...]that is thе end of this report. Right herе you wіll uncover sоme websites that any of uѕ belіevе you may value, just click all the links over[...]
Definitely an arithmetic post. You add trouble, subtract pleasure, divide attention, and multiply ignorance.
[...]listed below are a couple of urls to web-sites we connect to for the fact we believe they are worthy of checking out[...]
[...] Every once in a while we choose blogs that we read. Listed below are the latest sites that we choose [...]…
Can anyone see these goosebumps from this incredible post.
[...]if you want to read more then I recommend thе following[...]
[...]web sites worth going to[...]
[...]the time to read or visit the content or sites we have linked to below the[...]
[...]free sponsored backlinks who definitely have prior to this related to resulting from free of charge advancement[...]
TV Lamps - TV Lamps (12/12/2011 @ 06:48)
The Truth behind Television Replacement Lamps.
Keep working ,great job!
Its hard to find informative and accurate information but here I found
[...]I ѕаw someone preaching about thіѕ on Weebly and yes it linked to[...]
[...]just below, are some totally unrelated sites to ours, however, they are definitely worth checking out[...]
[...]how сomе sоme blogs inside оf а blogroll don't hаve thеіr hottest post listed and thе lіke do? How tо change that?[...]
[...]usually posts some very interesting stuff like this. If you’re new to this site[...]…
[...]always a big fan of linking to bloggers that I love but don’t get a lot of link love from[...]…
[...]here are some links to sites that we link to because we think they are worth visiting[...]…
[...]Here are some of the sites we recommend for our visitors[...]…
[...]just below, are some totally unrelated sites to ours, however, they are definitely worth checking out[...]
[...]below you’ll find the link to some sites that we think you should visit[...]…
[...]loads addiitional information for this types of area of interest on websites, observe[...]
All in one place solutions for all your TV lamps needs.
red duvet - bird supplies deals (16/12/2011 @ 23:19)
[...]the time to read or visit the content or sites we have linked to below the[...]
gi diet - living dining deals (16/12/2011 @ 23:26)
[...]just below, are some totally unrelated sites to ours, however, they are definitely worth checking out[...]
[...]the time to read or visit the content or sites we have linked to below the[...]…
[...] Wonderful story, reckoned we could combine a few unrelated data, nevertheless really worth taking a look, whoa did one learn about Mid East has got more problerms as well [...]…
Thanks for taking the time to provide us all with the info!
Now is the time if ever you want to read a story like this.
[...]always a big fan of linking to bloggers that I love but don’t get a lot of link love from[...]…
Thanks for taking the time to provide us all with the info!
I am regularly proclaiming that its difficult to get good help, but here is
[...]I consider be in agreement i can go this year.[...]
windows 8 - windows 8 (25/12/2011 @ 02:22)
This used to be a really perfect article. I truly enjoyed it and feature beneficial it to all of my readers.
Huper Optik Ceramic Window Films are low glare and block over 99% of harmful UV Rays.
Including Blinds, Shades, Shutters and Draperies. Serving Fairfax Virginia.
[...]while the sites we link to below are completely unrelated to ours, we think they are worth a read, so have a look[...]
[...]while the sites we link to below are completely unrelated to ours, we think they are worth a read, so have a look[...]
[...]plz visit my website and leave an awful comment! all its called aboutJoeJonas.weebly[...]
Jordan 45 - Air Jordan 18 (30/12/2011 @ 02:32)
[...]I care for up and down visualizing because as people read it is eaiser to take up mental a photo the position to your head.[...]
[...]directly below are a handful of urls to online websites we link to for the fact we think these are worthwhile visiting[...]
twinks - Great article (04/01/2012 @ 13:26)
Perfect work you have done, this site is really cool with fantastic info .
You have observed very interesting details! ps nice internet site.
I was reading the news and I saw this really cool info
I saw this really good post today.
[...]Very good intro. cant wait all around take all my copy!!![...]
[...]the time to read or visit the content or sites we have linked to below the[...]
I like to look in various places on the web, regularly I will just go to Digg and follow thru
I am regularly proclaiming that its difficult to procure quality help, but here is
[...]congrats guys. see you on top your big day![...]
I am constantnly saying that its hard to find quality help, but here is
[...]listed below are a few urls to places which I connect to since we think they really are truly worth browsing[...]
Oak Doors - Wikia (18/01/2012 @ 18:01)
Wika linked to this website
sex kontakte - Thumbs up (19/01/2012 @ 11:44)
I saw this really good post today.
Its hard to find informative and precise information but here I noted
[...]here are some links to sites that we link to because we think they are worth visiting[...]…
[...]the time to read or visit the content or sites we have linked to below the[...]…
i must say fantastic article
[...]Here is a Great Blog You Might Find Interesting that we Encourage You[...]…
[...]Here is a Great Blog You Might Find Interesting that we Encourage You[...]…
While I was browsing today I saw a excellent post concerning
Oak Interior Doors - Wikia (25/01/2012 @ 18:08)
Wika linked to this site
I must comment good post gamevui
[...]below you’ll find the link to some sites that we think you should visit[...]…
I want to comment fantastic foums truyen la
[...] Every once in a while we choose blogs that we read. Listed below are the latest sites that we choose [...]…
I want to say this is best site bongda bong da xaluan
I must say this is fantastic images truyen tranh xaluan
Thanks for taking the time to provide us all with the info!
[...]please visit the sites we follow, including this one, as it represents our picks from the web[...]……
I linked to your site
[...]Wartrol Scam genital warts in the mouth[...]
While I was surfing yesterday I noticed a excellent post about
[...]these are a handful of links to web sites I always link to because we think they really are seriously worth browsing[...]
wartrol buy - wartrol review (02/02/2012 @ 11:55)
[...]Wartrol genital wart specialist[...]
[...]Buy Wartrol warts no more[...]
[...]we like to honor other sites on the web, even if they aren’t related to us, by linking to them. Below are some sites worth checking out[...]
[...]read the content we have linked to below[...]
[...]here are some links to sites that we link to because we think they are worth visiting[...]
This is one awesome blog article.Thanks Again. Fantastic.
Kamasz - Kamasz (03/02/2012 @ 05:34)
[...]here are some links to sites that we link to because we think they are worth visiting[...]
[...]here are some links to sites that we link to because we think they are worth visiting[...]
[...]listed below are a handful of references to internet websites that we connect to for the fact we think they will be well worth checking out[...]
[...]the time to read or visit the content or sites we have linked to below the[...]
I saw a writer writing about this on Tumblr and it linked to
Laisser un commentaire
  • Nom *

  • Email *

  • Homepage

  • Commentaire *

  • * = champs requis


  • Je suis amnésique