Why is this a constant?

25 views
Skip to first unread message

Ildar Khakimov

unread,
Jul 29, 2017, 4:38:23 PM7/29/17
to AdWords API Forum
Just curios, the PHP examples include a class called GetAdGroups

Which goes like

class GetAdGroups {
  const CAMPAIGN_ID = "";

Why is CAMPAIGN_ID a constant? It's a variable that should be changeable, it's not like an API key or something. Just trying to understand the logic behind this.

Ivan Bautista

unread,
Jul 31, 2017, 1:19:12 AM7/31/17
to AdWords API Forum
Hi Ildar,

Please note that all code samples from the client libraries are mainly used as reference for development. Thus, you may modify them according to what best suit your application requirements. If you want to set the CAMPAIGN_ID as a non-constant variable, then you may do so.

Let me know if you have any other AdWords API related questions.

Regards,
Ivan 
AdWords API Team

Ildar Khakimov

unread,
Jul 31, 2017, 12:25:43 PM7/31/17
to AdWords API Forum
Sure and that's why I wrote "i'm just curios" :)

Is this some kind of a security thing? I discussed this on a few forums and normally we hard code values like API keys using a constant, why use a constant for values that change like CAMPAIGN_ID? 

Thanet Knack Praneenararat (AdWords API Team)

unread,
Aug 1, 2017, 1:50:44 AM8/1/17
to AdWords API Forum
Hello IIdar,

The constant in the code example serves some purposes:
  • It's used to highlight that this is where you change to your desired value. The code example can't be run as is if you don't change that.
  • Though it's true that the value can be changed (unlike API keys that are mostly fixed), but it's a constant in one program run--it's never changed once the program is executed.
Note that in our more generic examples, we do use normal variables for objects we got from the API server directly.

Hope this help clarify your curiosity. :)
Please let me know if you have further questions.

Regards,
Thanet, AdWords API Team
Reply all
Reply to author
Forward
0 new messages