Google Cloud Storage PHP Client on a server

This example uses, PHP 5.4+ syntax. I used composer for loading up the client.

Access the Google Developers Console and go to the APIs & Auth > Credentials page. Click Create new Client ID and select Service Account. That will download a key file that we will need to put somewhere accessible by the script. I’m putting it in the same folder for this example, but you don’t want it downloadable. Next click聽Create new Key and select聽Server Key. The following constants are just straight copies from this page, except the project id, which is found as the Project Number on the Overview page.

The second parameter of Google_Auth_AssertionCredentials constructor is an array of services/APIs that you want to access. All the examples I found listed URLS, but I found that they are usually a constant on each service’s class.

11 thoughts on “Google Cloud Storage PHP Client on a server”

  1. Hey man, how r u!, I have a new problem this simple upload only lets me upload files under 5MB, i need to do it for bigger files, u have read about the Resumable File Upload but I don’t understand this 馃檨

    Do u have an example like this?


    Leo Reply:

    I haven’t messed with that. I’m thinking the 5MB limit is the upload or post limit from the PHP side though. I’ve done many files larger than 5MB without needing to do anything special.


  2. This code is outside of google cloud, is on another hosting service

    $google_cert = new Google_Auth_AssertionCredentials( GAPI_EMAIL_ADDRESS, [Google_Service_Storage::DEVSTORAGE_FULL_CONTROL], file_get_contents(‘KEY.p12’));


    Leo Reply:

    The reason is that you are using PHP 5.3 or earlier. You have to use the old array notation.

    $google_cert = new Google_Auth_AssertionCredentials(GAPI_EMAIL_ADDRESS, array(Google_Service_Storage::DEVSTORAGE_FULL_CONTROL), file_get_contents('KEY.p12'));


  3. Hello Leo, Im having this horrible error every couple of days.
    – The first time i have fixed it by creating again, (API Key, OAuth 2.0 client IDs and Service accounts).

    – but now i already get the same error, is it a bug or something like that??

    Ill try checking inside Permissions, but i have “Can edit”.

    i dont understand 馃檨 馃檨 Help Me Please!


  4. I have test it from another IP and then it works! , can google cloud block my ip?


Leave a Reply

Your email address will not be published. Required fields are marked *