fork download
  1. require __DIR__ . '/vendor/autoload.php'; // Google Drive API
  2.  
  3. // HTTPS Authentication
  4. $masterToken = getMasterTokenForAccount("your_username@gmail.com", "your_password");
  5. $appSignature = '38a0f7d505fe18fec64fbf343ecaaaf310dbd799';
  6. $appID = 'com.whatsapp';
  7. $accessToken = getGoogleDriveAccessToken($masterToken, $appID, $appSignature);
  8.  
  9. if ($accessToken === false) return;
  10.  
  11. // Initializing the Google Drive Client
  12. $client = new Google_Client();
  13. $client->setAccessToken($accessToken);
  14. $client->addScope(Google_Service_Drive::DRIVE_APPDATA);
  15. $client->addScope(Google_Service_Drive::DRIVE_FILE);
  16. $client->setClientId(""); // client id and client secret can be left blank
  17. $client->setClientSecret(""); // because we're faking an android client
  18. $service = new Google_Service_Drive($client);
  19.  
  20. // Print the names and IDs for up to 10 files.
  21. $optParams = array(
  22. 'spaces' => 'appDataFolder',
  23. 'fields' => 'nextPageToken, files(id, name)',
  24. 'pageSize' => 10
  25. );
  26. $results = $service->files->listFiles($optParams);
  27.  
  28. if (count($results->getFiles()) == 0)
  29. {
  30. print "No files found.\n";
  31. }
  32. else
  33. {
  34. print "Files:\n";
  35. foreach ($results->getFiles() as $file)
  36. {
  37. print $file->getName() . " (" . $file->getId() . ")\n";
  38. }
  39. }
  40.  
  41. /*
  42. $fileId = '1kTFG5TmgIGTPJuVynWfhkXxLPgz32QnPJCe5jxL8dTn0';
  43. $content = $service->files->get($fileId, array('alt' => 'media' ));
  44. echo var_dump($content);
  45. */
  46.  
  47. function getGoogleDriveAccessToken($masterToken, $appIdentifier, $appSignature)
  48. {
  49. if ($masterToken === false) return false;
  50.  
  51. $url = 'https://android.clients.google.com/auth';
  52. $deviceID = '0000000000000000';
  53. $requestedService = 'oauth2:https://w...content-available-to-author-only...s.com/auth/drive.appdata https://w...content-available-to-author-only...s.com/auth/drive.file';
  54. $data = array('Token' => $masterToken, 'app' => $appIdentifier, 'client_sig' => $appSignature, 'device' => $deviceID, 'google_play_services_version' => '8703000', 'service' => $requestedService, 'has_permission' => '1');
  55.  
  56. $options = array(
  57. 'http' => array(
  58. 'header' => "Content-type: application/x-www-form-urlencoded\r\nConnection: close",
  59. 'method' => 'POST',
  60. 'content' => http_build_query($data),
  61. 'ignore_errors' => TRUE,
  62. 'protocol_version'=>'1.1',
  63. //'proxy' => 'tcp://127.0.0.1:8080', // optional proxy for debugging
  64. //'request_fulluri' => true
  65. )
  66. );
  67. $context = stream_context_create($options);
  68. $result = file_get_contents($url, false, $context);
  69. if (strpos($http_response_header[0], '200 OK') === false)
  70. {
  71. /* Handle error */
  72. print 'An error occured while requesting an access token: ' . $result . "\r\n";
  73. return false;
  74. }
  75.  
  76. $startsAt = strpos($result, "Auth=") + strlen("Auth=");
  77. $endsAt = strpos($result, "\n", $startsAt);
  78. $accessToken = substr($result, $startsAt, $endsAt - $startsAt);
  79.  
  80. return "{\"access_token\":\"" . $accessToken . "\", \"refresh_token\":\"TOKEN\", \"token_type\":\"Bearer\", \"expires_in\":360000, \"id_token\":\"TOKEN\", \"created\":" . time() . "}";
  81. }
  82.  
  83. function getMasterTokenForAccount($email, $password)
  84. {
  85. $url = 'https://android.clients.google.com/auth';
  86. $deviceID = '0000000000000000';
  87. $data = array('Email' => $email, 'Passwd' => $password, 'app' => 'com.google.android.gms', 'client_sig' => '38918a453d07199354f8b19af05ec6562ced5788', 'parentAndroidId' => $deviceID);
  88.  
  89. $options = array(
  90. 'http' => array(
  91. 'header' => "Content-type: application/x-www-form-urlencoded\r\nConnection: close",
  92. 'method' => 'POST',
  93. 'content' => http_build_query($data),
  94. 'ignore_errors' => TRUE,
  95. 'protocol_version'=>'1.1',
  96. //'proxy' => 'tcp://127.0.0.1:8080', // optional proxy for debugging
  97. //'request_fulluri' => true
  98. )
  99. );
  100. $context = stream_context_create($options);
  101. $result = file_get_contents($url, false, $context);
  102. if (strpos($http_response_header[0], '200 OK') === false)
  103. {
  104. /* Handle error */
  105. print 'An error occured while trying to log in: ' . $result . "\r\n";
  106. return false;
  107. }
  108.  
  109. $startsAt = strpos($result, "Token=") + strlen("Token=");
  110. $endsAt = strpos($result, "\n", $startsAt);
  111. $token = substr($result, $startsAt, $endsAt - $startsAt);
  112.  
  113. return $token;
  114. }
Success #stdin #stdout 0.03s 25988KB
stdin
Standard input is empty
stdout
require __DIR__ . '/vendor/autoload.php'; // Google Drive API

// HTTPS Authentication
$masterToken = getMasterTokenForAccount("your_username@gmail.com", "your_password");
$appSignature = '38a0f7d505fe18fec64fbf343ecaaaf310dbd799';
$appID = 'com.whatsapp';
$accessToken = getGoogleDriveAccessToken($masterToken, $appID, $appSignature);

if ($accessToken === false) return;

// Initializing the Google Drive Client
$client = new Google_Client();
$client->setAccessToken($accessToken);
$client->addScope(Google_Service_Drive::DRIVE_APPDATA);
$client->addScope(Google_Service_Drive::DRIVE_FILE);
$client->setClientId("");    // client id and client secret can be left blank
$client->setClientSecret(""); // because we're faking an android client
$service = new Google_Service_Drive($client);

// Print the names and IDs for up to 10 files.
$optParams = array(
    'spaces' => 'appDataFolder',
    'fields' => 'nextPageToken, files(id, name)',
    'pageSize' => 10
);
$results = $service->files->listFiles($optParams);

if (count($results->getFiles()) == 0) 
{
    print "No files found.\n";
} 
else 
{
    print "Files:\n";
    foreach ($results->getFiles() as $file) 
    {
        print $file->getName() . " (" . $file->getId() . ")\n";
    }
}

/*
$fileId = '1kTFG5TmgIGTPJuVynWfhkXxLPgz32QnPJCe5jxL8dTn0';
$content = $service->files->get($fileId, array('alt' => 'media' ));
echo var_dump($content);
*/

function getGoogleDriveAccessToken($masterToken, $appIdentifier, $appSignature)
{
    if ($masterToken === false) return false;

    $url = 'https://android.clients.google.com/auth';
    $deviceID = '0000000000000000';
    $requestedService = 'oauth2:https://w...content-available-to-author-only...s.com/auth/drive.appdata https://w...content-available-to-author-only...s.com/auth/drive.file';
    $data = array('Token' => $masterToken, 'app' => $appIdentifier, 'client_sig' => $appSignature, 'device' => $deviceID, 'google_play_services_version' => '8703000', 'service' => $requestedService, 'has_permission' => '1');

    $options = array(
        'http' => array(
            'header' => "Content-type: application/x-www-form-urlencoded\r\nConnection: close",
            'method' => 'POST',
            'content' => http_build_query($data),
            'ignore_errors' => TRUE,
            'protocol_version'=>'1.1',
             //'proxy' => 'tcp://127.0.0.1:8080', // optional proxy for debugging
             //'request_fulluri' => true
        )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    if (strpos($http_response_header[0], '200 OK') === false) 
    { 
        /* Handle error */
        print 'An error occured while requesting an access token: ' . $result . "\r\n";
        return false;
    }

    $startsAt = strpos($result, "Auth=") + strlen("Auth=");
    $endsAt = strpos($result, "\n", $startsAt);
    $accessToken = substr($result, $startsAt, $endsAt - $startsAt);

    return "{\"access_token\":\"" . $accessToken . "\", \"refresh_token\":\"TOKEN\", \"token_type\":\"Bearer\", \"expires_in\":360000, \"id_token\":\"TOKEN\", \"created\":" . time() . "}";
}

function getMasterTokenForAccount($email, $password) 
{
    $url = 'https://android.clients.google.com/auth';
    $deviceID = '0000000000000000';
    $data = array('Email' => $email, 'Passwd' => $password, 'app' => 'com.google.android.gms', 'client_sig' => '38918a453d07199354f8b19af05ec6562ced5788', 'parentAndroidId' => $deviceID);

    $options = array(
        'http' => array(
            'header' => "Content-type: application/x-www-form-urlencoded\r\nConnection: close",
            'method' => 'POST',
            'content' => http_build_query($data),
            'ignore_errors' => TRUE,
            'protocol_version'=>'1.1',
             //'proxy' => 'tcp://127.0.0.1:8080', // optional proxy for debugging
             //'request_fulluri' => true
        )
    );
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    if (strpos($http_response_header[0], '200 OK') === false) 
    { 
        /* Handle error */
        print 'An error occured while trying to log in: ' . $result . "\r\n";
        return false;
    }

    $startsAt = strpos($result, "Token=") + strlen("Token=");
    $endsAt = strpos($result, "\n", $startsAt);
    $token = substr($result, $startsAt, $endsAt - $startsAt);

    return $token;
}