googleads / google-ads-php

Google Ads API Client Library for PHP
https://developers.google.com/google-ads/api/docs/client-libs/php
Apache License 2.0
290 stars 260 forks source link

The GetCampaigns.php returns empty response! #52

Closed mohamadx closed 5 years ago

mohamadx commented 5 years ago

Hello

When I try to get my campaign list from my test manager account I get the empty result:

php examples/BasicOperations/GetCampaigns.php --customerId 8920....

Result:

[2019-04-08 12:38:58] google-ads.DEBUG: Request
-------
Method Name: /google.ads.googleads.v1.services.GoogleAdsService/Search
Host: googleads.googleapis.com
Headers: {
    "x-goog-api-client": "gl-php\/7.1.27-1+ubuntu16.04.1+deb.sury.org+1 gapic\/ gax\/0.38.0 grpc\/1.19.0",
    "developer-token": "REDACTED"
}
Request: {"customerId":"8920.....","query":"SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id","pageSize":1000}

Response
-------
Headers: {
    "content-disposition": "attachment",
    "request-id": "iKHs-LW8SgJVQn3boN8g1Q",
    "date": "Mon, 08 Apr 2019 12:38:58 GMT",
    "alt-svc": "quic=\":443\"; ma=2592000; v=\"46,44,43,39\""
}
Response: {"fieldMask":"campaign.id,campaign.name"}

Can anyone explain me what's the problem?

fiboknacky commented 5 years ago

You manager account shouldn't contain any campaigns. That's why you don't get any campaigns back. So, it works as intended.

Best, Knack

mohamadx commented 5 years ago

No!
I have 2 campaigns in my account, see below image:

Screen Shot 2019-04-08 at 17 31 49
fiboknacky commented 5 years ago

In principle, campaigns can belong to only client accounts. If your customer ID does belong to the manager account, it works as intended. If you want to get those campaigns back, you need to specify your client account as a customer ID instead.

mohamadx commented 5 years ago

I'm confused!
I did create a test manager account in google ads and after this create an account for creating a campaign.
I did create 2 campaigns.
As you can see in the below image, I have 2 ID:
892-081-8015 -> My customer ID 310-069-0566 -> My client(?) account(?) ID

Which I should use for getting my campaigns list? However, When I pass 310-069-0566 (without dashes) as the my customer ID, I did get error: The caller does not have permission

Screen Shot 2019-04-08 at 17 45 03
fiboknacky commented 5 years ago

First, 892-081-8015 is a manager account and 310-069-0566 is a client account.

I highly recommend reviewing this article for more information about manager accounts. In short, manager accounts don't often contain data directly on its own. They're used to manage other client accounts. On the other hand, client accounts are the one containing many pieces of information and can gain performance data.

So, in this case, the account that contain campaigns is 310-069-0566 and you should use this customer ID instead.

Regarding the permission error, it can result by many causes. The most probable cause would be you've not passed the login customer ID as a header. You can see how to set the login customer ID here.

For further help on this, please post on this forum, as your question is more involved with the product in general.

Best, Knack