在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:googleads/googleads-php-lib开源软件地址:https://github.com/googleads/googleads-php-lib开源编程语言:PHP 100.0%开源软件介绍:Google Ads API PHP Client LibraryThis project hosts the PHP client library for the various SOAP-based Ads APIs (AdWords and Ad Manager) at Google.
Requirements and Preparation
Getting startedCopy the sample Downloading this libraryThere are three ways of downloading this library as described below.
Note
Using composer requireThe steps below download this library as a third-party library for your projects.
The library will be downloaded by Composer and stored under the
Using git cloneThis method is suitable for those who want to alter or contribute to this library (e.g., submitting pull requests) or wish to try our examples. All files in this repository will be downloaded.
Downloading a compressed tarballThis is suitable for those who only want to try out the AdWords API with this
client library. The extracted directory of the tarball will contain only the
Setting up your OAuth2 credentialsThe AdWords and Ad Manager APIs use OAuth2 as the authentication mechanism. Follow the appropriate guide below based on your use case. If you're accessing an API using your own credentials... If you're accessing an API on behalf of clients... Basic usageThe best way to learn how to use this library is to review the examples for your product.
The following snippet of code from the BasicOperations/GetCampaigns.php example for AdWords gives you an idea of how to use this library. The usage pattern is similar for Ad Manager. use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201802\cm\CampaignService;
use Google\AdsApi\AdWords\v201802\cm\OrderBy;
use Google\AdsApi\AdWords\v201802\cm\Paging;
use Google\AdsApi\AdWords\v201802\cm\Selector;
use Google\AdsApi\Common\OAuth2TokenBuilder;
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile()
->build();
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->build();
$adWordsServices = new AdWordsServices();
$campaignService = $adWordsServices->get($session, CampaignService::class);
// Create selector.
$selector = new Selector();
$selector->setFields(array('Id', 'Name'));
$selector->setOrdering(array(new OrderBy('Name', 'ASCENDING')));
// Create paging controls.
$selector->setPaging(new Paging(0, 100));
// Make the get request.
$page = $campaignService->get($selector);
// Do something with the $page. The builder's
It is highly recommended that you use an WSDL objects with names that are reserved PHP keywordsClass namesNote that some WSDL object types have names that are reserved PHP keywords and need to be augmented when used as PHP class names. The following is a list of these occurences. Constant namesSome WSDL enum values have names that are reserved PHP keywords and need to be
modified when used as PHP constant names. For example, LoggingThis library conforms to PSR-3 for logging and provides the following loggers: AdWords
Ad Manager
In general, each logger logs a summary and debug message for events (e.g., a SOAP API call). The level at which messages are logged depends on whether the event succeeded.
Configuring loggingBy default, each of the library loggers logs to
You can configure some options for these default loggers in the [LOGGING]
; Optional logging settings.
soapLogFilePath = "path/to/your/soap.log"
soapLogLevel = "NOTICE" If you need to further customize logging, you can specify your own logger entirely by providing a logger that implements LoggerInterface in either the AdWords or Ad Manager session builders: $session = (new AdWordsSessionBuilder())
...
->withSoapLogger(new MyCustomSoapLogger())
->withReportDownloaderLogger(new MyCustomReportDownloaderLogger())
->build(); UtilitiesWe provide some utilities in this client library for helping you use features in the AdWords and Ad Manager API more conveniently. Check out the following wikis for details: ReportingWhen downloading reports, you can set additional stream context
options using the $options = [
'stream_context' => [
'http' => ['timeout' => 120]
]
];
$requestOptionsFactory = new RequestOptionsFactory($session, $options);
$reportDownloader = new ReportDownloader($session, $requestOptionsFactory); SSL CA filesPHP >= v5.6 automatically sets
If this library can't find a CA bundle on your system, you'll get an error message similar to this:
CA file issues can also cause an error like this:
To remedy, see Steps for troubleshooting CA file issues. DocumentationPHPDoc for this library can be found in the gh-pages branch of this repository and can be viewed at: General AdWords and Ad Manager API documentation can be found on our Google Developers site: Coding StyleWe use PSR-2 as a coding style standard. Assuming that you're at the root directory of your project, to check for coding style violations, run
To automatically fix (fixable) coding style violations, run
Getting supportFor client library specific bug reports, feature requests, and patches, create an issue on the issue tracker. For general AdWords and Ad Manager API questions, bug reports, or feature requests, post to our forums: Announcements and updatesFor general ads API and client library updates and news, follow: API deprecation schedules can be found at: |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论