(1/1) ApiException[InternalApiError.UNEXPECTED_INTERNAL_API_ERROR @ com.google.ads.api.services.common.error.InternalApiError.<init>(InternalApiErro] |
---|
$userLocations = [];
$userAccounts = [];
foreach($gooleMyBusiness->accounts->listAccounts() as $account) {
$locations = $gooleMyBusiness->accounts_locations->listAccountsLocations($account->name);
$userAccounts[] = $account;
foreach($locations->getLocations() as $location) {
$userLocations[] = $location;
}
}
$this->dispatch(
new AssociationGoogleMyBusinessLocationExtensions([
'gmbEmailAddress' => 'te...@gmail.com'
'gmbBusinessAccountId' => explode('/', $userAccounts[0]->name)[1],
], $adwordsAccount)
);ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーclass AssociationGoogleMyBusinessLocationExtensions
{
use DispatchesJobs;
protected $_params;
protected $_adWordsServices;
protected $_session;
const PLACEHOLDER_LOCATION = 7;
// The maximum number of CustomerFeed ADD operation attempts to make before
// throwing an exception.
const MAX_CUSTOMER_FEED_ADD_ATTEMPTS = 10;
const BUSINESS_ACCOUNT_IDENTIFIER = null;
/**
* Create a new command instance.
*
* @param array $params
*/
public function __construct(array $params, $adwordsAccount)
{
$this->_params = $params;
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile()
->build();
$this->_gmbAccessToken = $oAuth2Credential->fetchAuthToken()['access_token'];
$session = (new AdWordsSessionBuilder())
->fromFile()
->withOAuth2Credential($oAuth2Credential)
->withClientCustomerId($adwordsAccount->account_id)
->withSoapLogger(new Logger('', [new NullHandler()]))
->withReportDownloaderLogger(new Logger('', [new NullHandler()]))
->build();
$this->_session = $session;
$this->_adWordsServices = new AdWordsServices;
}
/**
* @return \App\ORM\Customer
*
*/
public function handle()
{
//dd($this->_params);
$feedService = $this->_adWordsServices->get($this->_session, FeedService::class);
// Create a feed that will sync to the Google My Business account specified
// by $gmbEmailAddress. Do not add FeedAttributes to this object, as AdWords
// will add them automatically because this will be a system generated feed.
//dd($this->_params);
$gmbFeed = new Feed();
$gmbFeed->setName('Google My Business feed #' . uniqid());
$feedData = new PlacesLocationFeedData();
$feedData->setEmailAddress($this->_params['gmbEmailAddress']);
//$feedData->setBusinessAccountIdentifier(Null);
$feedData->setBusinessAccountIdentifier($this->_params['gmbBusinessAccountId']);
//$feedData->setBusinessAccountIdentifier($this->_params['gmbBusinessAccountId']);
// Optional: specify labels to filter Google My Business listings. If
// specified, only listings that have any of the labels set are
// synchronized into FeedItems.
$feedData->setLabelFilters(['Stores in New York City']);
$oAuthInfo = new OAuthInfo();
$oAuthInfo->setHttpMethod('GET');
$oAuthInfo->setHttpRequestUrl('https://www.googleapis.com/auth/adwords');
$oAuthInfo->setHttpAuthorizationHeader(
sprintf('Bearer %s', $this->_gmbAccessToken));
$feedData->setOAuthInfo($oAuthInfo);
$gmbFeed->setSystemFeedGenerationData($feedData);
// Since this feed's feed items will be managed by AdWords,
// you must set its origin to ADWORDS.
$gmbFeed->setOrigin(FeedOrigin::ADWORDS);
// Create a feed operation and add it to the list.
$operation = new FeedOperation();
$operation->setOperator(Operator::ADD);
$operation->setOperand($gmbFeed);
$operations = [$operation];
// Add the feed on the server. Since it is a system generated feed, AdWords
// will automatically:
// 1. Set up the FeedAttributes on the feed.
// 2. Set up a FeedMapping that associates the FeedAttributes of the feed
// with the placeholder fields of the LOCATION placeholder type.
$addedFeed = $feedService->mutate($operations)->getValue()[0];
printf("Added GMB feed with ID %d\n", $addedFeed->getId());
}
}