Skip to content

Instantly share code, notes, and snippets.

@divinity76
divinity76 / LoginGmail.php
Last active August 3, 2020 17:02
login to gmail.com with curl, pretending to be a browser.
<?php
declare(strict_types = 1);
// header ( "content-type: text/plain;charset=utf8" );
// https://github.com/divinity76/hhb_.inc.php/blob/master/hhb_.inc.php
require_once ('hhb_.inc.php');
function loginGmail(string $username, string $password, string $recoveryEmailChallengeAnswer) : \hhb_curl
{
$hc = new hhb_curl('', true);
$hc->setopt_array(array(
@karlkranich
karlkranich / sheets-api-test-part2.php
Last active February 2, 2023 21:39
(obsolete due to Google changes) PHP code to use the Google Spreadsheets API with an OAuth Service Account. For more info, see http://karl.kranich.org/google-sheets-api-php
<?php
// Section 5: edit a row
// You'll need to get the etag and row ID, and send a PUT request to the edit URL
$rowid = 'cre1l'; // got this and the etag from the table data output from section 3
$etag = 'NQ8VCRBLVCt7ImA.';
$url = "https://spreadsheets.google.com/feeds/list/$fileId/od6/private/full/$rowid";
$method = 'PUT';
$headers = ["Authorization" => "Bearer $accessToken", 'Content-Type' => 'application/atom+xml', 'GData-Version' => '3.0'];
$postBody = "<entry xmlns=\"http://www.w3.org/2005/Atom\" xmlns:gsx=\"http://schemas.google.com/spreadsheets/2006/extended\" xmlns:gd=\"http://schemas.google.com/g/2005\" gd:etag='&quot;$etag&quot;'><id>https://spreadsheets.google.com/feeds/list/$fileid/od6/$rowid</id><gsx:gear>phones</gsx:gear><gsx:quantity>6</gsx:quantity></entry>";
$req = new Google_Http_Request($url, $method, $headers, $postBody);