I can't get contentOwnerID on youtube API - youtube-api

I can't get contentOwnerID on youtube API.
$contentOwnersListResponse = $youtubePartner->contentOwners->listContentOwners(array('fetchMine' => true));
$contentOwnerId = $contentOwnersListResponse['items'][0]['id'];
this code can't get contentOwnerID. I'm using sample code from here [Uploading and Monetizing a Video
]1.
Why I can't get contentOwnerID? Please help me.

Related

API gives constant subscriber count

I am trying to make a web app which shows real time subscribercount of a youtube channel.But it just shows me a constant number.The number of subscribers are not updated in next call of API.
I have written this function to get subs.I have tried with ID as well still no updates.Help me out.
Javascript
function getsubscribers(username, element) {
let url = `https://www.googleapis.com/youtube/v3/channels?key=${KEY}&forUsername=${username}& part=statistics`;
fetch(url)
.then((res) => res.json())
.then((data) => {
element.innerText = data.items[0].statistics.subscriberCount;
});
}
YouTube analytics has the same issue.
This is because the YouTube API is not a realtime api, the data seams to be updated once a day.

Can't retrieve some comments from Youtube video by CommentThreads:list

Please, help with Youtube API. CommentThreads:list doesn't give all TopLevelComments. I find several missing CommentID.
Example: comments correctly opens by URL:
https://www.youtube.com/watch?v=hySk1m57PAQ&lc=z12jjlsjrlmsgp4lu23rhxbgmrenxl5py04
,
but throw API function this commentID return no data:
https://www.googleapis.com/youtube/v3/commentThreads?maxResults=99&alt=json&part=id%2Csnippet&key=<...key...>&textFormat=plainText&id=z12jjlsjrlmsgp4lu23rhxbgmrenxl5py04
What wrong this it? How can I get this comment?

YouTube API V3 - Get recommended video for new feed

As YouTube official documentation about implement and immigrate to API V3, they said:
YouTube Data API (v2) functionality: Retrieve video recommendations
The v3 API does not retrieve a list that only contains videos recommended for the current API user. However, you can use the v3 API to find recommended videos by calling the activities.list method and setting the home parameter value to true.
But now the parameter home has been deprecated too.
Currently, when I set the home parameter to true, I only retrieve the recently uploaded video in the channel: Popular video in YouTube. There are no video with snippet.type=recommendation at all.
I need to show recommended videos of authenticated user in new feed, but seem like this feature is completely deprecated by YouTube.
Anyone has solution for that?
Thanks first!
Unfortunately, I can't find any documentation or example about this feature. It seems that this has been deprecated. However, you may check this documentation with sample JSON structure that shows the format of a activities resource such as recommendation:
"recommendation": {
"resourceId": {
"kind": string,
"videoId": string,
"channelId": string,
},
Hope this helps!
I found this youtubes search api. All we need to do is put a video id in the relatedToVideoId and it'll giveout a list of videos related to it.
The docs for the api include a way to test the request. code samples there show how to set 'mine' for an authenticated request.
youtube activities
This is android sample code. it would need to be in some background thread. The setmine = true on the channelList response is like the home (I think). Was not sure if your implementation was for the web or an app.
this is android code:
YouTube youtube = new YouTube.Builder(transport, jsonFactory,
credential).setApplicationName(getString(R.string.app_name))
.build();
YouTube.Activities.List activities;
ActivityListResponse activityListResponse = null;
List<ActivityData> activitiesData = new ArrayList<ActivityData>();
try {
/*
* Now that the user is authenticated, the app makes a
* channels list request to get the authenticated user's
* channel. Returned with that data is the playlist id for
* the uploaded videos.
* https://developers.google.com/youtube
* /v3/docs/channels/list
*/
ChannelListResponse clr = youtube.channels().list("contentDetails")
.setMine(true).execute();
activities = youtube.activities().list("id,snippet,subscriberSnippet");
activities.setChannelId(clr.getItems().get(0).getId());
activities.setMaxResults((long) 50);
activityListResponse = activities.execute();
ArrayList<String> subscriptionListIdentifier = new ArrayList<String>()
,listTitles = new ArrayList<String>()
,listThumbnails = new ArrayList<String>();
List<Activity> results = activityListResponse.getItems();
for (Activity activity : results) {
listTitles.add(activity.getSnippet().getTitle());
listThumbnails.add(activity.getSnippet().getThumbnails().getDefault().getUrl());
subscriptionListIdentifier.add(activity.getId());
//if ("public".equals(playlist.getStatus()
// .getPrivacyStatus())) {
ActivityData data = new ActivityData();
data.setActivity(activity);
activitiesData.add(data);
//}
}
return activitiesData;
You can retrieve them using the following API call:
GET https://www.googleapis.com/youtube/v3/activitiespart=snippet%2CcontentDetails&channelId={channel—_Id}&maxResults=25&regionCode=tw&key={YOUR_API_KEY}

Youtube Video Upload in User Wall

I used the Facebook PHP SDK to upload a YouTube Video in the FB user wall.
I used the "source" option in "/USER_ID/feed/" of Graph API.
USER_ID is the logged in user's Facebook ID.
My code was working fine.
But Facebook made some changes in their API and the code is not working anymore.
Only the Youtube video image is showing but the Youtube video is not playing in facebook.
My code looks like this:-
$params = array(
'access_token' => $fbToken,
'message' => $name.' has shared a Vhybe',
'link' => $link,
'name' => 'Vhybe Social',
'caption' => $title,
'description' => $content
);
$sourceUrl = "https://www.youtube.com/v/".$videoId;
$imageUrl = "http://i4.ytimg.com/vi/".$videoId."/default.jpg";
$params['source'] = $sourceUrl;
$params['picture'] = $imageUrl;
$result = $facebook->api(
'/'.$userId.'/feed/',
'POST',
$params
);
I tried the "Graph API explorer" tool from the Facebook developer tools section
URL => https://developers.facebook.com/tools/
But i am getting the same results.
If the above process to upload Youtube video to user wall has been deprecated can you please suggest me an alternate process.
Thanks in advance.
Sincerely,
Sourav Mukherjee
Well the above code is working fine again.
I did not make any changes in my code.
Looks like Facebook corrected their own issue.
Sincerely,
Sourav Mukherjee

Get a playlist entry by ID with YouTube API (PHP)?

I'm currently in the middle of a project that involves YouTube API. I'm using the Zend Gdata, and everything has gone nicely until this.
I need to get a Zend_Gdata_YouTube_PlaylistListEntry based on the ID of the playlist. I have managed to retrieve the videos with some fiddling:
$feed = $yt->getVideoFeed('http://gdata.youtube.com/feeds/api/playlists/'.$id.'?v=2');
$playlist = new Zend_Gdata_YouTube_PlaylistListEntry($feed->getDOM());
However, I need to use the method $playlist->getPlaylistVideoFeedUrl(), and it returns NULL in this case.
Any help regarding this is appreciated =)
Got it:
$url = 'http://gdata.youtube.com/feeds/api/playlists/'.$input['id'].'?v=2';
$feed = $yt->getPlaylistVideoFeed($url);

Resources