Skip to main content

Why can't I instantiate Api()?

Comments

5 comments

  • Itay Taragano

    I assume you're using the v1 of our PHP SDK?

    If so, please make sure that in your `conposer.json` file, you have the following set-up

    {
      "require": {
        "cloudinary/cloudinary_php": "^1"
      }
    }

    And then run:

    composer update

    Lastly, you'd need to set your credentials differently, either via an environment variable, or inside the application via 'Config'. For more information:
    https://cloudinary.com/documentation/php1_integration#setting_the_cloudinary_url_environment_variable

    Please let us know if this works for you?

    0
  • Anthony Bartoli

    Thanks for your help! I got interesting results.

    First, I want to use v2 of the PHP SDK because v1 is "legacy." And this is where I'm having problems.

    I updated my composer.json to v1 as you instructed and this code works:


    require "vendor/autoload.php";

    putenv("CLOUDINARY_URL=cloudinary://my_key:my_secret@my_cloud_name");

    $api = new \Cloudinary\Api();

    $folders = $api->root_folders();
    echo "<pre>";
    var_dump($folders);
    echo "</pre>";


    But because I want to use v2 of the SDK, I updated my composer back to:

    {
    "require": {
    "cloudinary/cloudinary_php": "^2"
    }
    }

    I run "composer update" to go back to v2 and I get the same error as my original post.

    I suppose I can use v1 for now but I don't understand why this simple code fails on v2 but not v1.

    0
  • Tia Esguerra

    Hi Anthony. 
    I'm not too familiar with PHP, but I will do my best to look into this and see if I can provide some answers. In the meantime,  and since you mention that you would prefer to use v2 of the SDK, I'm wondering if you've had a chance to look over our migration guide here https://cloudinary.com/documentation/php2_migration 

    0
  • Anthony Bartoli

    Thanks @Tia. I'll check out the migration guide.

    0
  • Erwin Lukas

    Hi Anthony,

    SDK v1 and v2 has a different syntax and there are some code migration that you need to perform (as mentioned by Tia above) if you have an existing code that's written with PHP v1 SDK. 

    However, if you just start a new project with PHP v2 SDK, I would recommend to check the following documentation: https://cloudinary.com/documentation/php_integration#installation.

    And I think you could also benefit to take the following course to get started with PHP v2: https://training.cloudinary.com/courses/introduction-for-api-users-and-php-developers

    On this course, it will guide you on how to setup your environment, upload, transformations, and other topics.

    Hope this helps!

    0

Post is closed for comments.