YouTube Api 3.0 - php

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'));

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

Is it possible to return the category ID of a video when using the listSearch() function in the YouTube PHP API?

I don't know why, but in order to use the API update to update the description of a video in your library you have to provide more than just the ID, you have to provide: the title, the ID, and the category ID. Why you need more than just the unique video ID is beyond me.
When I request a list of videos using the following parameters:
$queryParams = [
'forMine' => true,
'q' => $q,
// 'fields' => 'items(id,snippet/title,snippet/description)', <- would like to specify categoryId here
'type' => 'video',
'maxResults' => 50
];
$response = $service->search->listSearch('snippet', $queryParams);
The returned list provides the Title and the ID but not the Category ID. Actually I don't know of any way of getting the category ID besides opening the video in your YouTube dashboard, looking at the category, and the comparing it to a list like this one
So, is their a way of updating a video's description without needing the category ID, or is there a way of acquiring that category ID using the API?
Here is how I am attempting to update the description.
// Auth the client
$service = new Google_Service_YouTube($client);
// Define the $video object, which will be uploaded as the request body.
$video = new Google_Service_YouTube_Video();
// Set the ID
$video->setId($video_id);
// Add 'snippet' object to the $video object.
$videoSnippet = new Google_Service_YouTube_VideoSnippet();
$videoSnippet->setCategoryId('<HOW TO GET THIS?>');
$videoSnippet->setDescription('Test Description');
$videoSnippet->setTitle($video_title);
$video->setSnippet($videoSnippet);
$response = $service->videos->update('snippet', $video);
PS, can someone who has the right privilege add the youtube-php-api tag?
UPDATE:
You cannot retrieve the Category ID using the SEARCH api, you must use the LIST api. What this means is that if you want to update the description of a video that you searched for, you need use 3 separate APIs. Here is how I used the LIST api to retrieve the category id:
$client = google_authenticate();
$service = new Google_Service_YouTube($client);
$queryParams = [
'id' => $video_id,
'fields'=>'items(snippet/categoryId)'
];
$response = $service->videos->listVideos('snippet', $queryParams);
return $response['items'][0]['snippet']['categoryId'];
According to the docs, indeed you have to set categoryId for each video that you intend to update its snippet part.
Use VideoCategories endpoint to obtain a list of categories (along with corresponding IDs) available for your region.
Update:
If needing to get the category ID of a given (already existing) video, use the Videos endpoint, and lookup for the property items[].snippet.categoryId.

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);

Why Can't I Get Google Adwords Video Campaigns?

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.

v3 Youtube API - How to modify the category of a new broadcast

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);

Categories