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"
    }
}
2
  • Quick searching couldn't find nothing related in google-api-php-client samples nor a iam folder in php-docs-samples. I believe other languages like Go or Python have "more/better maintained" client libraries, check this example. Commented Oct 5, 2019 at 14:06
  • I also tried the nodejs examples, which work fine. Commented Oct 5, 2019 at 18:29

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

stackoverflow.com/questions/63971562/… Please look at this issue, share your suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.