Google adwords api php примеры

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Google Ads API Client Library for PHP

License

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

* Fixed the case when system package grpc version not found. Also, added unit tests for the check added in #922. To do so, I separated the version fetching logic into a class named `Dependencies`, so we can do dependency injection to `GoogleAdsClientBuilder`. * Fixed the copyright years.

Git stats

Files

Failed to load latest commit information.

README.md

Google Ads API Client Library for PHP

This project hosts the PHP client library for the Google Ads API.

IMPORTANT The Google Ads API client library for PHP has been updated to require PHP version 8 as the minimum version, as announced in #880. This means that the final version of the library that supports PHP 7 is v19.2.0, which supports Google Ads API v12 to v14.

Google Ads API v14 is scheduled to be sunset by the end of May 2024. Therefore, PHP 7 users have about 11 months to migrate to PHP 8 in order to continue using the library without disruption.

  • Distributed via Composer and Packagist.
  • Easy management of credentials.
  • Easy creation of Google Ads API service clients.
  • Both 32-bit and 64-bit PHP systems are supported but we highly recommend to use 64-bit if you can. This is because many fields of the Google Ads API are typed as 64-bit integers and casting their values to int instead of float from 32-bit systems can lead to issues. The largest integer value supported in 32-bit PHP systems is usually 2147483647, see the predefined constant PHP_INT_MAX for more details.
  • This library depends on Composer. If you don’t have it installed on your computer yet, follow the installation guide for Linux/Unix/OS X or installation guide for Windows. For the rest of this guide, we’re assuming that you’re using Linux/Unix/OS X and have Composer installed globally, thus, your installed Composer is available on the command line as composer .
  • System requirements and dependencies can be found in composer.json of this library.
    • PHP: You can find the required minimum PHP version in «php» under the require key of composer.json . We usually set it to the minimum PHP version for which the PHP development team still provide security fixes. Whenever such a version is sunset, we’ll update the composer file accordingly. Currently, the update frequency is around once a year based on the official schedule. Visit this page for introduction to PHP.
    • gRPC: To install the gRPC PHP extension, make sure to meet any additional requirements listed in the project’s documentation. You can learn more about how gRPC is used by this library by reading our Transport guide. It usually take minutes to install using PECL :
      1. Install the extension using the command sudo pecl install grpc .
      2. Add a line extension=grpc.so to the php.ini file.
      3. Run php -i | grep grpc in a terminal: it is well installed and configured if it returns something
    • Protobuf: To install the Protobuf PHP extension, make sure to meet any additional requirements listed in the project’s documentation. If you encounter any error during the installation, you can skip this step and the PHP implementation will be used instead. You can learn more about how Protobuf is used by this library by reading our Protobuf implementations guide. It usually take minutes to install using PECL :
      1. Install the extension using the command sudo pecl install protobuf .
      2. Add a line extension=protobuf.so to the php.ini file.
      3. Run php -i | grep protobuf in a terminal: it is well installed and configured if it returns something

    Follow the below steps if you want to try our code examples.

      Clone this project in the directory of your choice via:

    git clone https://github.com/googleads/google-ads-php.git 
    • composer.json : the composer file, which holds the requirements of this library.
    • src : source code of the library.
    • tests : tests of the library code.
    • examples : many examples that demonstrate how to use the library to execute common use cases via the Google Ads API.
    • metadata : some metadata files used internally by the source code. They’re automatically generated files, so you shouldn’t modify them.
    • Copy the sample google_ads_php.ini to your home directory. This library determines the home directory of your computer by using EnvironmentalVariables::getHome() .
    • Follow the instructions at https://developers.google.com/google-ads/api/docs/oauth/cloud-project to create an OAuth2 client ID and secret for the installed application OAuth2 flow.
    • Run the GenerateUserCredentials example, which will prompt you for your OAuth2 client ID and secret.
    • Copy the output from the last step of the example into the google_ads_php.ini file in your home directory. Don’t forget to fill in your developer token too.
    php examples/BasicOperations/GetCampaigns.php --customerId

    Installing the library as your project’s dependency

    1. Change into the root directory of your project.
    2. Run composer require googleads/google-ads-php at the command prompt. This will install this library and all its dependencies in the vendor/ directory of your project’s root directory.
    3. Set up your OAuth2 credentials like described in the previous section.
    4. You can now use this library by importing its classes like shown in the code examples.

    To issue requests via the Google Ads API, you first need to create a GoogleAdsClient.

    For more information on how to configure a client when instantiating it, see the configuration guide.

    Once you have an instance of GoogleAdsClient , you can obtain a service client for a particular service using one of the get. ServiceClient() methods.

    There are different types of transport that can be used. See the Transport guide for more information.

    Protobuf is used regardless of the transport used to request the Google Ads API.

    See the Protobuf guide for more information.

    Running in a Docker container

    Источник

    How to use Google Ads API in PHP

    # 5 steps guide how to use googleads-php-lib

    If you already tried to follow Make Your First API Call

    and video with talk through instead of walkthrough of the steps and you felt confused and unclear, then this tutorial is for you!

    # Step 1. Create Manager Account

    You must have a Google Ads Manager Account to apply for access to the API.

    . This link will create an AdWords manager account. This is the one you should use if you are going through the AdWords API Sign Up guide to request a developer token.

    Manager Accounts cannot be created using the same email address as an existing Google Ads account.

    You must therefore use an email address that hasn’t already been associated with a Google Ads account to create your Manager Account.

    Sign up for AdWords API access through your Manager Account. Sign in, then navigate to TOOLS & SETTINGS > SETUP > API Center. The API Center option will appear only for Google Ads Manager Accounts.

    Get Developer token

    API Access Screenshot

    # Step 2. Generate Test Client Id

    Create a test manager account

    You should see «Test account» in right top corner.

    Take number client id (number above email)

    Test Account Screenshot

    # Step 3. Create credentials

    # Step 4. Generate refresh token

    from the example directory by following this section

    Copy the following lines to your 'adsapi_php.ini' file: clientId = "xxxx.apps.googleusercontent.com" clientSecret = "L-xxxxxxx" refreshToken = "1//xxxxx" 

    # Step 5. Execute test call.

    composer require googleads/googleads-php-lib 

    There should be no errors.

    Now you can move forward and implement Conversion tracking

    following official documentation and examples

    Please write down in comments below if it actually worked for you and if you have any questions. I spent around 3 days to figure out how to configure it just to make a first test call. Be careful with datetime format 😉

    You might also like

    Источник

    Читайте также:  Чем запустить install php
Оцените статью