Why Can't I Get Google Adwords Video Campaigns? - php

There seems to be an issue for getting all Adwords campaigns. When I currently try to retrieve all campaigns, I don't get the video campaigns. My understanding through the documentation was that it shouldn't be this much work. Another SO user had the similar problem Whats happens with GET Video Adwords Campaigns
Is this a Google Adwords error, deprecation error, or something that I messed up on my end?
require_once('Google/Api/Ads/AdWords/Lib/AdWordsUser.php');
$oauth2Info = array('client_id' => $client_id, 'client_secret' => $client_secret, 'access_token' => $access_token);
$user = new AdWordsUser();
$user->SetDeveloperToken($developer_token);
$user->SetOAuth2Info($oauth2Info);
$customerService = $user->GetService('CustomerService', 'v201509');
$customer = $customerService->get();
$user->SetClientCustomerId($customer->customerId);
$campaignService = $user->GetService('CampaignService', 'v201509');
$selector = new Selector();
$selector->fields = array('Id', 'Name');
$selector->ordering[] = new OrderBy('Name', 'ASCENDING');
$selector->paging = new Paging(0, 500);
$page = $campaignService->get($selector);
The page value only contains non-video campaigns. I'm in the process of upgrading API, so maybe it can't get videos for API version v201509?

Google Adwords API does not currently support video campaigns.

You can collect some data thanks to the video performance report : https://developers.google.com/adwords/api/docs/appendix/reports/video-performance-report.
This is the only data you can get on TrueView (video Adwords) through the API.

Related

How to get Locations list in Google My Business API | PHP

How can I get locations list in Google My Business API. Where I retrieved account list but I can't figure out how to retrieve location.
Here is my code where I am getting accounts list
define('GOOGLE_CLIENT_ID', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
define('GOOGLE_CLIENT_SECRET', 'XXXXXXXXXXXXX');
// Create Client Request to access Google API
$client = new Client();
$client->setApplicationName('my-app');
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setRedirectUri('https://example.com/callback');
$client->addScope('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/business.manage');
$client->setAccessType('offline'); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->setAccessToken($accessToken);
$service = new \Google_Service_MyBusinessAccountManagement($client);
$accounts = $service->accounts->listAccounts()->getAccounts(); // get accounts
To get google locations,
you can use this PHP My Business file to make things little easier.
First change you scope to ttps://www.googleapis.com/auth/plus.business.manage then include the file and create a object of Google_Service_MyBusiness with you client and then do like this.
$mybusinessService = new Google_Service_MyBusiness($client);
// Get the first account in the accounts array
$accounts = $mybusinessService->accounts;
$accountsList = $accounts->listAccounts()->getAccounts();
$account = $accountsList[0];
// Get the first location in the locations array
$locations = $mybusinessService->accounts_locations;
$locationsList = $locations->listAccountsLocations($account->name)->getLocations();
$location = $locationsList[0];
var_export($location);
With this process you can also able to get google reviews.
For more details check this Google Business API documentation.
Hope it can help
"It's correct!!!
I increase this at my code:
$optParams = array(
'readMask' => 'name',
);
$list_accounts_response = $my_business_account->accounts_locations->listAccountsLocations("accounts/114893266195214446586", $optParams);
var_dump($list_accounts_response);
Thank you.."
source : https://github.com/googleapis/google-api-php-client/issues/2213#issuecomment-1042785983

How to update Facebook campaign detail using Facebook marketing api

I am using the Facebook marketing api to create a campaign, adset, creative and ads and I am using the PHP sdk 3.0 to manage them in Facebook.
I can create them successfully. Here is code to create a campaign:
$fields = array();
$params = array(
'name' => 'API Test - vish',
'objective' => 'CONVERSIONS',
'status' => 'PAUSED',
);
try{
$campaign = $this->ad_account->createCampaign($fields,$params);
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
echo $campaign->id;
I want to update details of a campaign.
I did some research and found this link, which states, that it is possible to update campaign details, but it does not provide a correct way to do it.
Anybody please let me know how I can update Facebook campaign details using its api.
I know it is old question but I had the same issue and I've solved it this way:
$campaign = new Campaign($campaignId);
$campaign->updateSelf($fields, $params); // in $params are updated properties
Maybe it will help someone.

How to create local post on google using PHP MyBusiness API?

I want to create local post on google using google's PHP My Business API V4.
Sample code is below
$mybusinessService = new \Google_Service_MyBusiness($client);
$local = new \Google_Service_MyBusiness_LocalPost();
$path = $locname.'/localPosts';
$response = $mybusinessService->accounts_locations_localPosts->create($path,$local);
where $locname is string of accounts/locations id.
above code throws exception 'Request contains an invalid argument.'
I want to know that how to create post or post data using PHP api.
Any help would be appreciated.
For brands that have more than ten locations are not allowed to post on GMB through the API. Pull the location and check this flag $location->getLocationState()->getIsLocalPostApiDisabled().
Posting on GMB Ex.
$posts = $mybusinessService->accounts_locations_localPosts;
$newPost = new Google_Service_MyBusiness_LocalPost();
$newPost->setSummary("Order your Thanksgiving turkeys now!!");
$newPost->setLanguageCode("en-US");
$calltoaction = new Google_Service_MyBusiness_CallToAction();
$calltoaction->setActionType("ORDER");
$calltoaction->setUrl("http://google.com/order_turkeys_here");
$newPost->setCallToAction($calltoaction);
$media = new Google_Service_MyBusiness_MediaItem();
$media->setMediaFormat("PHOTO");
$media->setSourceUrl("https://www.google.com/real-turkey-photo.jpg");
$newPost->setMedia($media);
$listPostsResponse = $posts->create($location_name, $newPost);

How to toggle on Monetise with ads option on YouTube with API

I am building an application that uploads videos to YouTube using PHP Google Client library. I was able to upload videos but couldn't toggle on the Monetise checkbox. There is very little information on the web.
I found this link to be helpful. http://www.techtonet.com/youtube-upload-videos-with-partner-api-in-php/#ipt_kb_toc_51_6
But I couldn't managed to do this.
Please help with this.
// Create a claim resource. Identify the video being claimed, the asset
// that represents the claimed content, the type of content being claimed,
// and the policy that you want to apply to the claimed video.
$claim = new Google_Service_YouTubePartner_Claim();
$claim->setAssetId($assetId);
$claim->setVideoId($videoId);
$claim->setPolicy($policy);
$claim->setContentType("audiovisual");
// Insert the created claim.
$claimInsertResponse = $this->_youtubePartner->claims->insert($claim,
array('onBehalfOfContentOwner' => $contentOwnerId));
# Enable ads for the video. This example enables the TrueView ad format.
$option = new Google_Service_YouTubePartner_VideoAdvertisingOption();
//$option->setAdFormats(array("overlay", "trueview_instream", "standard_instream"));
$option->setAdFormats(array("trueview_instream", "standard_instream"));
$setAdvertisingResponse = $this->_youtubePartner->videoAdvertisingOptions->update(
$videoId, $option, array('onBehalfOfContentOwner' => $contentOwnerId));
For me is working with this code
$youtubePartner = new \Google_Service_YouTubePartner($this->client);
$asset = new \Google_Service_YouTubePartner_Asset();
$metadata = new \Google_Service_YouTubePartner_Metadata();
$youtubePartner = new \Google_Service_YouTubePartner($this->client);
$metadata->setTitle("Asset Title"));
$metadata->setDescription("AssetDescription");
$asset->setMetadata($metadata);
$asset->setType("web");
$assetInsertResponse = $youtubePartner->assets->insert($asset, [
'onBehalfOfContentOwner' => $this->contentOwnerId
]);
$assetId = $assetInsertResponse['id'];
$ratio = 100;
$type = "exclude";
$territories = [];
$owners = new \Google_Service_YouTubePartner_TerritoryOwners();
$owners->setOwner($this->contentOwnerId);
$owners->setRatio($ratio);
$owners->setType($type);
$owners->setTerritories($territories);
$ownership = new \Google_Service_YouTubePartner_RightsOwnership();
$ownership->setGeneral([$owners]);
$youtubePartner->ownership->update($assetId, $ownership, ['onBehalfOfContentOwner' => $contentOwnerId]);
$policy = new \Google_Service_YouTubePartner_Policy();
$policyRule = new \Google_Service_YouTubePartner_PolicyRule();
$policyRule->setAction("monetize");
$policy->setRules(array($policyRule));
$claim = new \Google_Service_YouTubePartner_Claim();
$claim->setAssetId($assetId);
$claim->setVideoId($videoId);
$claim->setPolicy($policy);
$claim->setContentType("audiovisual");
$claimInsertResponse = $youtubePartner->claims->insert($claim, [
'onBehalfOfContentOwner' => $contentOwnerId,
]);
If is not working for you put all code here, after uploading video, once you have videoId from Youtube.
You only need to change $videoId and $contentOwnerId
The code that shows you above is the part that corresponds only to the monetization. You need to have the video already uploaded to youtube. If you have the id of the video and contentOwnerId the code should work without changing anything else. Try only this part of the code and if it does not work for you, get me the answer of toutube to the following request
$claimInsertResponse = $youtubePartner->claims->insert($claim,
array('onBehalfOfContentOwner' => $contentOwnerId));
If successful, this method returns a claim resource in the response body. Otherwise it returns an error. If it returns an error, give me the error, so I can tell you what is happening.

Display Facebook ADs Statistics on webpage using Facebook Ads API in PHP

Does anyone know how to fetch all facebook ads statistics and display on webpage using Facebook Ads Api-PHP SDK. I am using this API and I am getting campaign details like name of campaign, id, status. but not able to get impressions,clicks, spent.
What I am doing let me share with you:
1) I am getting access token by authorizing user
2) After getting access token, I am using below code
$account = new AdAccount('act_XXXXXXXXXXXXXXX');
$account->read();
$fields = array(
AdCampaignFields::ID,
AdCampaignFields::NAME,
AdCampaignFields::OBJECTIVE,
);
$params = array(AdCampaignFields::STATUS => array(AdCampaign::STATUS_ACTIVE,AdCampaign::STATUS_PAUSED,),);
$campaigns = $account->getAdCampaigns($fields, $params);
/* Added By Jigar */
$campaign = new AdCampaign('XXXXXXXXXXXXXXXX');
$compainDetails = $campaign->read($fields);
3) then printing the array
echo "<pre>";
print_r($compainDetails);
exit;
If anyone know any suggestion in above code, please share. All code is in PHP. Dose anyone have any tutorial that fetch all above required data then share it
You could try to use the facebook insights api instead of $campaign->read. Here's an example:
https://developers.facebook.com/docs/marketing-api/insights/v2.5#create-async-jobs
What you have to do to get impressions, click and spent is to add these fields to the $fields param. In your case, the complete code should look like the following:
use FacebookAds\Object\Campaign;
use FacebookAds\Object\Values\InsightsLevels;
use FacebookAds\Object\Values\InsightsFields;
$campaign = new Campaign();
$fields = array(
InsightsFields::IMPRESSIONS,
InsightsFields::UNIQUE_CLICKS,
InsightsFields::CALL_TO_ACTION_CLICKS,
InsightsFields::INLINE_LINK_CLICKS,
InsightsFields::SOCIAL_CLICKS,
InsightsFields::UNIQUE_SOCIAL_CLICKS,
InsightsFields::SPEND,
);
$params = array(
'level' => InsightsLevels::CAMPAIGN,
);
$async_job = $campaign->getInsightsAsync($fields, $params);
$async_job->read();
I don't know what exactly the "click" param means for you, but if you take a look at all these click params, I'm sure you'll find it or you'll know how to calculate it.
For a complete list of fields available on insights objects, have a look at: https://github.com/facebook/facebook-php-ads-sdk/blob/master/src/FacebookAds/Object/Fields/InsightsFields.php
Hope that helps.
Regards, Benjamin

Categories