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.
Related
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);
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.
I'm trying to define a category for a Youtube broadcast before the livestream is on air.
I've just followed Youtube API documentation and I didn't find any snipped definition for setCategory method in any class related to broadcasting or livestreaming.
According to that, the only way I've found to define a category is by creating a Google_Service_YouTube_VideoSnippet object. Something like this:
$videoSnippet = new Google_Service_YouTube_VideoSnippet();
$videoSnippet->setCategoryId("25");
// $snippet->setCategoryId($category);
$videoInsert = new Google_Service_YouTube_Video();
$videoInsert->setSnippet($videoSnippet);
$insertRequest = $youtube->videos->insert("snippet", $videoInsert);
$updateRequest = $youtube->videos->update("snippet", $videoInsert);
Here I let a link with the code that makes all the work:
What Am I doing wrongly? Is it a bug?
Thanks in advice.
UPDATE
Here bellow I paste the code that helped me solving this problem
$listResponse = $youtube->videos->listVideos("snippet",
array('id' => $broadcastsResponse['id']));
$video = $listResponse[0]['snippet'];
$video['categoryId'] = $category;
$updateResponse = $youtube->videos->update("snippet", $video);
You are using the right resource but in a wrong way.
1) you should first create the broadcast with liveBroadcasts.insert()
2) Then with the broadcast/video id you get from that operation, you call videos.update() in that update method, you can set the category.
pseudocode:
response = livebroadcast -> insert(broadcast);
video = new video();
video.id = response.broadcastId;
video->setCategory(25);
videos->update(video);
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
I am using API version 1.3 of mailchimp to create Campaign programmatically in PHP.
I am using MCAPI class method campaignCreate() to create campaign. Campaign is created successfully and it returns campaign id in response which is string.
But i need Web id (integer value of campaign id) so that I can use it to open that campaign using link on my website.
For example: lets say I want to redirect user to this link - https://us8.admin.mailchimp.com/campaigns/show?id=941117 and for that i need id value as 941117 when new campaign is created.For now i am getting it as string like 6ae9ikag when new campaign is created using mailchimp API
Please let me know if anyone knows how to get campaign web id (integer value) using Mailchimp API in PHP
Thanks
I found an answer so wanted to share here.Hope it helps someone
I get campaign id as a string when createCampaign() method of MCAPI class is used.
You need to use below code to get web id (integer value of campaign id)
$filters['campaign_id'] = $campaign_id; // string value of campaign id
$campaign = $api->campaigns($filters);
$web_id = $campaign['data'][0]['web_id'];
This worked for me.
Thanks
<?php
/**
This Example shows how to create a basic campaign via the MCAPI class.
**/
require_once 'inc/MCAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey
$api = new MCAPI($apikey);
$type = 'regular';
$opts['list_id'] = '5ceacbda08';
$opts['subject'] = 'Test Newsletter Mail';
$opts['from_email'] = 'guna#test.com';
$opts['from_name'] = 'guna';
$opts['tracking']=array('opens' => true, 'html_clicks' => true, 'text_clicks' => false);
$opts['authenticate'] = true;
$opts['analytics'] = array('google'=>'my_google_analytics_key');
$opts['title'] = 'Test Newsletter Title';
$content = array('html'=>'Hello html content message',
'text' => 'text text text *|UNSUB|*'
);
$retval = $api->campaignCreate($type, $opts, $content);
if ($api->errorCode){
echo "Unable to Create New Campaign!";
echo "\n\tCode=".$api->errorCode;
echo "\n\tMsg=".$api->errorMessage."\n";
} else {
echo "New Campaign ID:".$retval."\n";
}
$retval = $api->campaignSendNow($retval);
?>
The web_id is returned by mailchimp when a call is made to the creation end point.
$mcResponce = $mailchimp_api->campaigns->create(...);
$web_id = $mcResponce['web_id'];
See the documentation.