GGshow reloaded GGshow reloaded

October 19, 2015

PHP 400 Quota Exceeded in Analytics Data Import

Issue:

  • Google Analytics Data Import failed after 50 upload.
  • Unable to upload large file for Analytics Data Import.
  • Intermittent error 400 with Management API.
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/upload/analytics/v3/management/accounts/.../webproperties/.../customDataSources/.../uploads?uploadType=media: (400) Quota exceeded.' in /base/data/home/apps/.../google-api-php-client/src/Google/Http/REST.php:110 Stack trace: #0 /base/data/home/apps/.../google-api-php-client/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client)) #1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request)) #2 /base/data/home/apps/.../google-api-php-client/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array)

Reason:
There are limits and quotas for Google Analytics Configuration and Reporting API. When daily project requests and daily write requests exceeded limit, API will return error 400.

Solution:

  • Fine-tune your application for quota usage; or
  • Request additional quota; or
  • Go to bed, try again tomorrow 🙂

Reference:
Configuration and Reporting API Limits and Quotas

Filed under: Google Cloud Platform,PHP — Tags: , , , , — GG @ 5:14 pm

PHP 403 Insufficient Permission in Analytics Data Import

Issue:

PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling POST https://www.googleapis.com/upload/analytics/v3/management/accounts/.../webproperties/.../customDataSources/.../uploads?uploadType=media: (403) Insufficient Permission' in /base/data/home/apps/.../google-api-php-client/src/Google/Http/REST.php:110 Stack trace: #0 /base/data/home/apps/.../google-api-php-client/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client)) #1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request)) #2 /base/data/home/apps/.../google-api-php-client/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array) #3 /base/data/home/apps/.../google-api-php-client/src/Google/Http/REST.php(46): Google_Task_Runner->run() #4 /base/data/ in /base/data/home/apps/.../google-api-php-client/src/Google/Http/REST.php on line 110

Reason:
Insufficient permission to perform an API query

Solution:

  • Ensure sufficient account permission granted for the service account (???@developer.gserviceaccount.com).
  • Ensure proper scopes defined in Service Account Authentication (Google_Auth_AssertionCredentials).
    Use Google_Service_Analytics::ANALYTICS ( or “https://www.googleapis.com/auth/analytics” ) instead of Google_Service_Analytics::ANALYTICS_READONLY ( or “https://www.googleapis.com/auth/analytics.readonly” ) if you need to perform an edit operation, e.g. Data Import.

Reference:

April 23, 2015

Google cloud storage for static website hosting

Synopsis

  • Using Google Cloud Storage as low cost yet reliable website hosting service for static webpages / files.

Requirements

  1. To host a static website on Google Cloud Storage, you need to create a Cloud Storage bucket with the domain/subdomain name as the bucket name.
  2. To create a domain named bucket or any bucket name contains dot (.), you need to pass the domain name ownership verification at Google Webmaster Tools.
  3. There are several methods to verify your site, however since you are creating a new storage to host your web files, I assume that you do not have an existing web hosting storage to store your HTML files at the moment, options by adding Meta tag, HTML file, Google Analytics or Tag Manager code might not be possible. Hence, adding new DNS records could be the only option that works for everyone.

Steps

  1. Creating DNS records
    Two new DNS records need to be created.

    1. A CNAME record of your subdomain hostname (e.g. www) with canonical name c.storage.googleapis.com.
      Creating CNAME record for Google Cloud Storage bucket
    2. Another TXT or CNAME record need to be created for Google Webmaster Tools domain ownership verification.
  2. Verify domain ownership
    Add your site at Google Webmaster Tools and verify the site ownership.
    Google Webmaster Tools site ownership verification
  3. Create bucket
    At Google Developers Console, under Storage > Cloud Storage, create a new bucket.
    Creating new Google Cloud Storage bucket
  4. Upload your web files
    Upload files to Google Cloud Storage bucket
  5. Set files permission
    From Storage Browser, enable public link option for all web files.
    Google Cloud Storage public link
  6. Edit bucket website configuration
    Configure main page and custom 404 page for your website.
    Google Cloud Storage website configuration, main page and custom 404 page

Useful gsutil / gsutil.py commands
You can also change file permission and website configuration using gsutil command.

Configuring main page and custom 404 page:

gsutil web set -m index.html -e 404.html gs://www.ggshow.com

Enabling public read file permission for a single file:

gsutil acl set public-read gs://www.ggshow.com/file.html

Enabling public read file permission for all files in bucket:

gsutil acl set public-read gs://www.ggshow.com/*.*

Uploading local files to bucket

gsutil cp -R \var\www gs://www.ggshow.com

Copying an object (file or folder) from one bucket to another bucket

gsutil cp -R gs://www.ggshow.com/object gs://mybackup.ggshow.com

Moving files from one folder to another folder

gsutil -m mv  gs://www.ggshow.com/folder1/*.* gs://www.ggshow.com/folder2

List files in bucket

gsutil ls gs://www.ggshow.com

Reference

© 2024 GGSHOW | Powered by WordPress