1

I'm still stuck on this question and I'm rephrasing it after a bit more exploration.

I cannot find code examples for using google-api-php-client with v1 API methods like projects/setIamPolicy() On this example

The PHP example appears to be broken because $service->projects is undefined. The equivalent nodejs example "just works".

I've attempted to switch to the v1-master branch, but the same code is still incompatible. I've attempted some modifications to compensate for v2 authentication methods used in the example, but hit a dead end.

What is the proper way to use v1 methods via PHP?

EDIT It looks like this simple composer file is my solution:

{
    "require": {
        "google/apiclient": "^2.0",
        "google/apiclient-services": "0.50"
    }
}
g000m
  • 125
  • 1
  • 12
  • Quick searching couldn't find nothing related in [google-api-php-client samples](https://github.com/googleapis/google-api-php-client/tree/master/examples) nor a iam folder in [php-docs-samples](https://github.com/GoogleCloudPlatform/php-docs-samples/). I believe other languages like Go or Python have "more/better maintained" client libraries, check [this example](https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/iam/api-client/access.py). – fbraga Oct 05 '19 at 14:06
  • I also tried the nodejs examples, which work fine. – g000m Oct 05 '19 at 18:29

1 Answers1

1

After reproducing the documentation instructions, I came across the same error of undefined property $projects in $service. It seems that the documentation examples for PHP Cloud Resource Manager API v1 are defining classes (like $service = new Google_Service_CloudResourceManager($client);) that are actually implemented in v2.

v1 Library contains variables $organizations and $projects.

v2 Library contains variables $folders and $operations.

In the documentation example, the script tries to access $projects, using the v2 Class, where $projects doesn’t exist, but $folders and $operations do.

enter image description here

By using a version of google-api-php-client-services Library, which includes the latest version n of v1, you can access $folders, $liens, $operations, $organizations, $projects but still use V2 Classes of google-api-php-client.

  • https://stackoverflow.com/questions/63971562/how-to-create-project-in-google-console-cloud-platform-using-php-lib-programmati Please look at this issue, share your suggestion. – Bob Kris Sep 20 '20 at 10:10