Skip to content

Instantly share code, notes, and snippets.

@apocratus
apocratus / twitterData.gs
Last active September 11, 2020 16:56
Retrieve Twitter Profile & Posts data from API with Google Apps Script and save to Google Sheets
/**
* This function retrieves all your relevant profile data from the Twitter API and saves it to a Google Sheets spreadsheet. It
* checks the last inserted column and if the dates are the same it replaces the data. (Run trigger hourly for up-to-date data).
*
* You need to register a new app at https://apps.twitter.com/ add the consumer and secret key below and approve the app by
* running makeInitialAuthorizationRequest().
*
* The code below uses the OAuth1 library (Resources -> Libraries... -> Add a Library
* (use "1CXDCY5sqT9ph64fFwSzVtXnbjpSfWdRymafDrtIZ7Z_hwysTY7IIhi7s" as the identifying key)
*
@apocratus
apocratus / retrievePostsData.gs
Last active June 14, 2024 00:03
Retrieve Instagram Profile & Posts Data with Google Apps Script and save to Google Sheets
/**
* This function retrieves all your latest instagram posts from the Instagram API and saves it to a Google Sheets spreadsheet. It
* replaces all the previous data (Run hourly for up-to-date data).
*
* You need to register a new app at https://www.instagram.com/developer/clients/manage/ and generate a access token to use this.
* (http://bobmckay.com/web/simple-tutorial-for-getting-an-instagram-clientid-and-access-token/).
*
* This can be used to build a Google Data Studio report of your Instagram data.
*/
@apocratus
apocratus / scopes.txt
Created July 30, 2012 13:40
google API's - scope for oauth authentication
Google Reader https://www.google.com/reader/atom/
Google Reader https://www.google.com/reader/subscription/export
Google Analytics Data API https://www.google.com/analytics/feeds/
Google Sites Data API http(s)://sites.google.com/feeds/
Blogger Data API http://www.blogger.com/feeds/
Book Search Data API http://www.google.com/books/feeds/
Calendar Data API http(s)://www.google.com/calendar/feeds/
Contacts Data API http(s)://www.google.com/m8/feeds/
Content API for Shopping https://www.googleapis.com/auth/structuredcontent
Documents List Data API http(s)://docs.google.com/feeds/
@apocratus
apocratus / detect_mobiles.php
Created November 18, 2011 10:37
Mobile Phone Browser Detection
<?php
$useragent = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|
@apocratus
apocratus / image_resizer.php
Created June 9, 2011 14:51
resize image and create thumbnail (fixed width and height)
<?php
// Get the image and create a thumbnail
$img = imagecreatefromjpeg($_FILES["Filedata"]["tmp_name"]);
if (!$img) {
echo "ERROR:could not create image handle ". $_FILES["Filedata"]["tmp_name"];
exit( 0 );
}
$width = imageSX($img);
$height = imageSY($img);
@apocratus
apocratus / export_csv.php
Created April 22, 2011 10:10
Export MySQL to CSV (php script)
<?php
/* vars for export */
// database record to be exported
$db_record = 'XXXXXXXXX';
// optional where query
$where = 'WHERE 1 ORDER BY 1';
// filename for export
$csv_filename = 'db_export_'.$db_record.'_'.date('Y-m-d').'.csv';
// database variables