cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Curl and Google AdWords

From: Niklas Forsberg <niklas.forsberg_at_firstpoint.se>
Date: Mon, 25 Jun 2007 20:13:25 +0200

I am encountering problems when trying to create a function that
will automatically login to Google AdWords and curl a certain campaign
and then grab all data on that page for insertion in my personal database.

Logging in seems to work fine!
But when I attempt to proceed to a sub page I'll get redirected to a
"Moved Temporarily" page.

Here is the code I use for now:

> <?php
>
> // INIT CURL
> $ch = curl_init();
>
> // VERIFY SSL CERTIFICATE
> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
>
> // SET URL FOR THE POST FORM LOGIN
> curl_setopt($ch, CURLOPT_URL,
> 'https://www.google.com/accounts/ServiceLoginBoxAuth');
>
> // ENABLE HTTP POST
> curl_setopt ($ch, CURLOPT_POST, 1);
>
> // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
> curl_setopt ($ch, CURLOPT_POSTFIELDS,
> 'ifr=true&Email=info_at_roligahemsidor.se&Passwd=1989jeep&PersistentCookie=yes&rmShown=1&null=Logga+In');
>
> // IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
> curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
>
> // RETURN TRANSFER IN VARIABLE INSTEAD OF PRINTING IT OUT
> curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
>
> // EXECUTE 1st REQUEST (FORM LOGIN)
> $store = curl_exec ($ch);
>
> // SET FILE TO DOWNLOAD
> curl_setopt($ch, CURLOPT_URL,
> 'https://adwords.google.com/select/CampaignSummary');
>
> // RETURN TRANSFER IN VARIABLE INSTEAD OF PRINTING IT OUT
> curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
>
> // EXECUTE 2nd REQUEST (FILE DOWNLOAD)
> $content = curl_exec ($ch);
>
> // CLOSE CURL
> curl_close ($ch);
>
> // STOP THE REDIRECT-SHITTIE
> $content = str_replace('<body
> onload="insertLoadingMessage();redirect();"', '<body', $content);
>
> echo $content;
>
> ?>

So when I try to get page
"https://adwords.google.com/select/CampaignSummary" after loggin in
I will get the "Moved Temporarily" page, but I want the Campaign Summary
(or any other specified page) ofcourse!

Please help!

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2007-06-25