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);
Related
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
I need to update an upcoming Broadcast with YouTube Data API. I'm following this guide https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/update
Right now I can change all the snippet info with the PHP SDK, but I don't see anywhere how to add trough the API a list of emails who will have access to the private broadcast video (just how we can do trough the panel of YouTube):
My current PHP try is this:
$videoId = $mVideoLive->id;
$liveBroadcast = new Google_Service_YouTube_LiveBroadcast();
$liveBroadcast->setId($videoId);
$liveBroadcastSnippet = new \Google_Service_YouTube_LiveBroadcastSnippet();
$liveBroadcastSnippet->setTitle("Mi gran titulo");
$liveBroadcastSnippet->setDescription("Hola este es mi descripcion genial");
$datetime = new DateTime('2021-04-08 11:00:00');
$startTime = $datetime->format(DateTime::ATOM); // Updated ISO8601
$liveBroadcastSnippet->setScheduledStartTime($startTime);
$liveBroadcast->setSnippet($liveBroadcastSnippet);
$response = $service->liveBroadcasts->update("snippet", $liveBroadcast);
Any thoughts?
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.
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);
I have the authentication all working, but when i try to get a list of categories using the php library:
// $client is the google client object
$youtube = new Google_YoutubeService($client);
$youtube->videoCategories->listVideoCategories("id");
i get the response:
'Error calling GET https://www.googleapis.com/youtube/v3/videoCategories?part=id: (400) No filter selected'
There is no option in listVideoCategories for "filter", the only accepted params are $part and optional params...nothing to do with filters?
Apparently you need to need to provide either the category id's you want or the region for which you want all categories. You can try it and read the details here: https://developers.google.com/youtube/v3/docs/videoCategories/list
This should work:
// $client is the google client object
$youtube = new Google_YoutubeService($client);
$categories = $youtube->videoCategories->listVideoCategories('id', array('regionCode' => 'US'));