Closed antonioperic closed 9 years ago
Is it possible to include https://github.com/googleads/googleads-php-lib with Symfony2. I tried to install it with composer but I always get some error regarding namespaces. Please notice that Google Library doesn't use namespaces. I tried to set included path but didn't manage to get this working.
Does anyone knows how to pull this out/
This is error I got:
Compile Error: AdWordsSoapClientFactory::DoRequireOnce(): Failed opening required '/vagrant/vendor/googleads/googleads-php-lib/src/Google/Api/Ads/AdWords/Lib/../v201309/CampaignService.php' (include_path='/vagrant/vendor/googleads/googleads-php-lib/src:.:/usr/share/php:/usr/share/pear')
Also I added this to composer.json "classmap": ["vendor/googleads/googleads-php-lib/src/Google/Api/Ads/AdWords/Lib"]
There is an an experimental branch that uses proper namespace. It's not supported at the moment, but it'd be great to see how it would work.
https://github.com/googleads/googleads-php-lib/tree/experimental
You can find this in packagist as well https://packagist.org/packages/googleads/googleads-php-lib
I've been using this in my composer file for a while.
"require": {
"php": ">=5.3.2",
"googleads/googleads-php-lib": "~5.1,>=5.2.1"
},
This currently pulls in version 5.7.1 Once installed, everything is working as expected.
Here is my example code:
$mode = 'LIVE';
$adwords = new \AdWordsUser();
$adwords->LogErrors();
$adwords->SetUserAgent('PHP');
$adwords->SetClientCustomerId('123');
$adwords->SetOAuth2Info(
array(
'client_id' => 'id',
'client_secret' => 'secret',
'refresh_token' => 'refresh_token',
)
);
if ($mode == 'LIVE') {
$adwords->SetDeveloperToken('developer token');
$adwords->SetApplicationToken('application token');
} else {
if ($mode == 'SANDBOX') {
$adwords->SetDeveloperToken('username' . '++' . CURRENCY_FOR_SANDBOX);
}
}
$this->query(
$adwords->getService('CampaignService'),
array('Id', 'Name', 'Status', 'ServingStatus', 'StartDate', 'EndDate', 'BudgetId'),
array('accountId' => '123)
);
Though looking forward to proper namespaced code.
"require": {
"googleads/googleads-php-lib": "5.*"
},
"autoload": {
"classmap": [
"vendor/googleads/googleads-php-lib/src/Google/Api/Ads/Dfp/Lib",
"vendor/googleads/googleads-php-lib/src/Google/Api/Ads/Dfp/Util",
"vendor/googleads/googleads-php-lib/src/Google/Api/Ads/Common"
]
}
Then, in your PHP code:
use DfpUser;
$user = new DfpUser(...);
Of course, it won't be namespaced - but in reality your code with Symfony/Laravel should be prefixed with your own namespaces, thus it shouldn't conflict with Google PHP SDK ones.
By the way, I saw that autoload is in composer.json of the package already. So suppose you need only autoload the ones which are missing (was Util and Common in my case).
@YOzaz In your example you are using $this->query() can I ask what this is? I am trying to get this set up in Laravel so this is my final stumbling block.
@joshhornby not sure I follow - where do you see $this->query in my example?
$this->query(
$adwords->getService('CampaignService'),
array('Id', 'Name', 'Status', 'ServingStatus', 'StartDate', 'EndDate', 'BudgetId'),
array('accountId' => '123)
);
OK, it's @hackzilla example, not mine...
So it is! Sorry my bad one of them days
I'd say, stick into official Google examples - they work just fine: https://github.com/googleads/googleads-php-lib/blob/master/examples/AdWords/v201409/BasicOperations/AddCampaigns.php
It works perfectly with composer
Ah $this->query was a wrapper I'd forgotten to include.
/**
* Run query
*
* @param \AdWordsUser $service
* @param array $inject
*/
protected function query(\AdWordsUser $service, array $fields, array $inject = array())
{
// Create selector.
$selector = $this->buildSelector($fields);
// Make the get request.
$page = $service->get($selector);
$this->writeEntries($page, $inject);
}
writeEntries save the result to the disk, and $inject is there to allow me to add extra data.
Hi, what is the best way to integrate this lib with Sf2? Using composer or?