Automatically log in to Google Play download app report

Source: Internet
Author: User
Process
1. Sign in to Google Play

Three steps to sign in to Google Play
http://www.php.cn/
http://www.php.cn/://play.google.com/apps/publish/
http://www.php.cn/

2. Download the App report zip
3.unzip
Report

The code is as follows:

<?phpdefine (' Root_path ', DirName (__file__));d efine (' google_play_cookie_file ', ' google_play_cookie.txt ');/*** Login Google Play, download report, unzip* date:2013-04-17* author:fdipzone* version:1.0*/class Androidreportdow    nloader{private $username;    Private $password;    Private $dev _ACC;  /* init * @param string $username Google Play account * @param string $password Google Play password * @param        String $dev _acc Google Play Dev Account */Public function __construct ($username = ", $password =", $dev _acc= ") {        $this->username = $username;        $this->password = $password;    $this-&GT;DEV_ACC = $dev _acc; }/* * @param string $appname * @param string $sd Start date * @param string $ed End Date *                @param String $downloadFile Save the Zip name */Public Function run ($appname = ", $sd =", $ed = ", $downloadFile =") {        $package = $appname; $dim = ' Overall,country,language,os_version,deviCe,app_version,carrier '; $met = ' Daily_device_installs,active_device_installs,daily_user_installs,total_user_installs,active_user_        Installs,daily_device_uninstalls, Daily_user_uninstalls,daily_device_upgrades '; $met = "Daily_device_installs,current_device_installs,daily_user_installs,total_user_installs,current_user_ Installs,daily_device_uninstalls, Daily_user_uninstalls,daily_device_upgrades "; Google Modify 2013-08-06//login Google Play $this->loginauth ($this->username, $this-&GT;PASSW        ORD); Download report zip return $this->downloadreport ($package, $SD, $ed, $dim, $met, $this->dev_acc, $download        File);     }/* Login Google play,create cookies * @param string $username * @param string $password * @return Boolean */Private Function Loginauth ($username, $password) {//Step1 $MAINURL = "Https://play.google        . com/apps/publish/";        $ch = Curl_init (); Curl_setopt ($ch, Curlopt_url, $MAINURL);        curl_setopt ($ch, Curlopt_cookiejar, google_play_cookie_file);         curl_setopt ($ch, Curlopt_cookiefile, google_play_cookie_file);        curl_setopt ($ch, Curlopt_returntransfer, 1);        Curl_exec ($ch);        Curl_close ($ch);        Step 2 $serviceLoginUrl = "https://accounts.google.com/ServiceLogin?hl=en&continue=". $mainUrl;        $ch = Curl_init ();        curl_setopt ($ch, Curlopt_url, $SERVICELOGINURL);        curl_setopt ($ch, Curlopt_cookiejar, google_play_cookie_file);         curl_setopt ($ch, Curlopt_cookiefile, google_play_cookie_file);        curl_setopt ($ch, Curlopt_returntransfer, 1);        $serviceLoginRespHtml = curl_exec ($ch);        Curl_close ($ch); Preg_match ('/name= ' dsh "\s*id=" DSH "\s*value=" (. *?) " \s*/i ', $serviceLoginRespHtml, $matches);        Get dsh $dsh = $matches [1]; Preg_match ('/name= ' Galx "\s*value=" (. *?) " \s*/i ', $serviceLoginRespHtml, $matches); Get galx $galx = $matches [1];        Step 3 $loginGoogleUrl = "Https://accounts.google.com/ServiceLoginAuth";        $postFields = "referer=". $serviceLoginUrl;        $postFields. = "&allowautoredirect=false";        $postFields. = "&continue=". $mainUrl;        $postFields. = "&dsh=". $dsh;        $postFields. = "&h1=en";        $postFields. = "&galx=". $galx;        $postFields. = "&email=". $username;        $postFields. = "&passwd=". $password;        $postFields. = "&signin=sign+in";                $postFields. = "&persistentcookie=yes";        $ch = Curl_init ();        curl_setopt ($ch, Curlopt_url, $LOGINGOOGLEURL);        curl_setopt ($ch, Curlopt_post, 1);        curl_setopt ($ch, Curlopt_postfields, $postFields);        curl_setopt ($ch, Curlopt_cookiejar, google_play_cookie_file);         curl_setopt ($ch, Curlopt_cookiefile, google_play_cookie_file);         curl_setopt ($ch, Curlopt_header, true);         curl_setopt ($ch, curlopt_followlocation, true); Curl_Setopt ($ch, Curlopt_returntransfer, 1);        Curl_exec ($ch);        Curl_close ($ch);        Login Cookie Create success return true; }//Download report zip file Private Function Downloadreport ($package, $SD, $ed, $dim, $met, $dev _acc, $downloadFil E) {$url = "https://play.google.com/apps/publish/statistics/download?package={$package}&sd={$sd}&ed={$ed}                &dim={$dim}&met={$met}&dev_acc={$dev _ACC} ";        $fp = fopen ($downloadFile, "w");         $ch = Curl_init ();        curl_setopt ($ch, Curlopt_url, $url);         curl_setopt ($ch, Curlopt_returntransfer, 1);        curl_setopt ($ch, Curlopt_file, $fp);         curl_setopt ($ch, Curlopt_cookiefile, google_play_cookie_file);         Curl_exec ($ch);         Curl_close ($ch);        Fclose ($FP);        if (file_exists ($downloadFile)) {return true;    } return false; }/* Unzip report * @param string $path extracted path * @param string $downloadFile ZIP file */Public Function Unzipreport ($path, $downloadFile) {$exec = "unzip". $downloadFile. "-D". $path;        Shell_exec ($exec); Unlink ($downloadFile);//delete zip file}}//demo$username = ' testdev@gmail.com '; $password = ' abcd1234 '; $dev _acc = ' 12 345678901234567890 '; $appname = ' Com.testdev '; $sd = ' 20130417 '; $ed = ' 20130417 '; $downloadFile = ' testdev.zip '; $ Unzippath = Root_path. ' /testdev/'; $obj = new Androidreportdownloader ($username, $password, $dev _ACC); if ($obj->run ($appname, $SD, $ed, $ DownloadFile) {$obj->unzipreport ($unzipPath, $downloadFile);}? >


The above is automatically login Google Play download app report content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.