Why I sometime can`t delete subscriptions with youtube API V3? - youtube-api

I cannot remove some subscriptions from my list of subscriptions using youtube API V3 in PHP.
I run "check whether a subscription exists":
And I got answer:
**
* API response
*/
{
"kind": "youtube#subscriptionListResponse",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/vQg5vcdf3VcnZjlUVNARSwXX8tU\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#subscription",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/hMElmhRjuEbIkTVsj4iZTctj0jg\"",
"id": "lS7ClBpiilG9lCqFDoFRAmEypiwUQCact4W5ovUdXDE",
"snippet": {
"publishedAt": "2018-11-24T15:48:13.369Z",
"title": "Melieca and Kids",
After that i try delete subscription with ID "lS7ClBpiilG9lCqFDoFRAmEypiwUQCact4W5ovUdXDE"
function subscriptionsDelete($service, $id, $params) {
$params = array_filter($params);
$response = $service->subscriptions->delete(
$id,
$params
);
print_r($response);
}
subscriptionsDelete($service,
'lS7ClBpiilG9lCqFDoFRAmEypiwUQCact4W5ovUdXDE', array());
Response from youtube next:
{
"error": {
"errors": [
{
"domain": "youtube.subscription",
"reason": "subscriptionNotFound",
"message": "The subscription that you are trying to delete cannot be found. Check the value of the requests id parameter to ensure that it is correct."
}
],
"code": 404,
"message": "The subscription that you are trying to delete cannot be found. Check the value of the requests id parameter to ensure that it is correct."
}
}

Related

Why the request for collecting video IDs failed even if we are using `nextPageToken` written on the previous API result?

I'm creating YouTube's metrics monitoring feature. But I faced one confusing point while using YouTube Data API.
I want to retrieve all video IDs of one YouTube channel. I'm using Lambda for this process.
Before API call, I'm refreshing the access token every time within the Lambda.
In order to retrieve video IDs, I used search#list with the following parameters:
part: "id"
forMine: true
type: "video"
maxResults: 50
Then, we can get the result like the following:
{
"kind": "youtube#searchListResponse",
"etag": "7d3zMRNK3SwAAdU_zX5Yo9oMezw",
"nextPageToken": "SampleNextPageTokenParamXXX",
"pageInfo": {
"totalResults": 54,
"resultsPerPage": 50
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "etag1",
"id": {
"kind": "youtube#video",
"videoId": "sampleVideoId1"
}
},
{
"kind": "youtube#searchResult",
"etag": "etag2",
"id": {
"kind": "youtube#video",
"videoId": "sampleVideoId2"
}
},
...
}
Next, I tried to call the API with the following.
part: "id"
forMine: true
type: "video"
maxResults: 50
pageToken: "SampleNextPageTokenParamXXX" (added)
Then, we had two situations.
[Success case] Can get the result
[Failed case] Received the following result:
{
"error": {
"code": 400,
"message": "Therequestspecifiesaninvalidpagetoken.",
"errors": [
{
"message": "The request specifies an invalid page token.",
"domain": "youtube.parameter",
"reason": "invalidPageToken",
"location": "pageToken",
"locationType": "parameter"
}
]
}
}
I'm thinking this trouble happened from the access token's management solution, and this happened when the access token was inactivated by other processes working in parallel or Lambda's auto retrying process.
But if you have any solution other than the viewpoint of tokens, could you tell us? Best Regards.
It seems there was a transient (known within Google) issue, where the nextPageToken was not working properly.
Google's staff reported that it was fixed: '400 invalidPageToken' error returned for a valid Next Page Token

How do I list more than 50 Youtube videos in a channel using nextPageToken?

Using the following link, it listed all of my videos up to 50 results.
https://www.googleapis.com/youtube/v3/search?key={your_key_here}&channelId={channel_id_here}&part=snippet,id&order=date&maxResults=50
However, I wanted to list all of my videos in my channel so I added in the pageToken parameter (max 500 results). Here is the link I used by adding this in pageToken=nextPageToken
https://www.googleapis.com/youtube/v3/search?key={your_key_here}&channelId={channel_id_here}&part=snippet,id&order=date&maxResults=50&pageToken=nextPageToken
However, it gave me the following error
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "invalidPageToken",
"message": "The request specifies an invalid page token.",
"locationType": "parameter",
"location": "pageToken"
}
],
"code": 400,
"message": "The request specifies an invalid page token."
}
}
How is this supposed to be replicated so it will actually display the nextPageToken?
When you do a search, the results contain a nextPageToken field if there is another page of results.
{
"kind": "youtube#searchListResponse",
"etag": "\"cbz3lIQ2N25AfwNr-BdxUVxJ_QY/jtd94kasKWBOdCB882K5N-sSrnQ\"",
"nextPageToken": "CAEQAA",
"regionCode": "US",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 1
},
Setting pageToken in your next search call equal to that nextPageToken value will return the next page.
https://www.googleapis.com/youtube/v3/search?...&pageToken=CAEQAA

YouTube API 3 channels by username and id inconsistant

Why is it when I search for a channel by ID https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UU-tdS40X5ld-a4KfarLJuDw&key=[YOUR_API_KEY] I get no items returned.
But when I search by userName, it returns the channel ID that I just searched for https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=washingtonstateuniv&key=[YOUR_API_KEY]
when I search for a channel by ID .. I get no items returned.
Give the Try-it section for channels.list a try. I'm able to fetch JSON response by using these parameters:
part->contentDetails
id-> yourchannel ID
Authorize and Execute
The response it returned is not empty at all.
{
"kind": "youtube#channelListResponse",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/FiuYcDu7WFmoFVcLDRvENYGl_tQ\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/QjMybH99xT3x-znrh2Yerx_0DWk\"",
"id": "{my channel id}",
"snippet": {
"title": "{my channel name}",
"description": "",
"publishedAt": "2011-10-10T15:30:40.000Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"medium": {
"url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"high": {
"url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
}
},
"localized": {
"title": "{my channel name}",
"description": ""
}
}
}
]
}
That's a lot of results for me.
But when I search by userName, it returns the channel ID that I just
searched for.
In the channels.list try-it docs above, forUsername is defined as the forUsername parameter specifies a YouTube username, thereby requesting the channel associated with that username. So I think it's doing it's job.
Additional note on forUsername parameter is that's it's used to translate your arbitrary legacy YouTube username, that's the old Youtube accounts, into a channel ID using v3 of the API. More of that in Work with Channel IDs guide.
when I search by userName, it returns the channel ID that I just
searched for
You miss the important part to search by forUsername or channelID. That is snippet part, not contentDetails.
by forUsername :
https://www.googleapis.com/youtube/v3/channels?&part=snippet,id&forUsername=RealMiBs&title&key={YOUR_API_KEY}
by id channel:
https://www.googleapis.com/youtube/v3/channels?&part=snippet,id&id=UC_pwIXKXNm5KGhdEVzmY60A&title&key={YOUR_API_KEY}
That will exactly returned to like below:
{
"kind": "youtube#channelListResponse",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/VnicD0AYsCI7KlKKcdsmdIlWUMs\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/Nl4tuuOFwuPOdHmP_Ky3vuIQ2Gg\"",
"id": "UC_pwIXKXNm5KGhdEVzmY60A",
"snippet": {
"title": "CJENMMUSIC Official", <== Channel Name
"description": "Asia's No.1 Entertainment & Media Company", <== Channel Desctiption
"customUrl": "cjenmmusic", <=== Channel URL who has been qualified - to and for - claimed it
"publishedAt": "2011-03-25T04:48:40.000Z",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"medium": {
"url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"high": {
"url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
}
},
"localized": {
"title": "CJENMMUSIC Official",
"description": "Asia's No.1 Entertainment & Media Company"
}
}
}
]
}
While if you just pointing to contentDetails, it will return to almost nothing:
{
"kind": "youtube#channelListResponse",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/C7SnOhT2c-Fs2R9f6JlxlOPWc34\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/3RTKaEQC9GX8c58R2Bhd8G1y3zM\"",
"id": "UC_pwIXKXNm5KGhdEVzmY60A",
"contentDetails": { <============== detail contents
"relatedPlaylists": {
"uploads": "UU_pwIXKXNm5KGhdEVzmY60A",
"watchHistory": "HL",
"watchLater": "WL"
}
}
}
]
}

Unable to access Google Plus API in browser

i am working on to display wall posts (Stream) data using Google Plus API.
i have valid Client ID + API_KEY.
I am able to get response from Google Plus cloud console.i.e. by executing method I get Something like
Request
GET https://www.googleapis.com/plus/v1/people/myuserid/activities/public?maxResults=5&key={YOUR_API_KEY}
X-JavaScript-User-Agent: Google APIs Explorer
Response
200 OK
Show headers -
{
"kind": "plus#activityFeed",
"etag": "\"Mwea3qudNDf-hWWlPWi3n-YrU1Q/ovxXa0lmTRbwzkDa9o_iJ2pdFBs\"",
"nextPageToken": "CAIQgIi2z8bDugIgASgB",
"title": "Google+ List of Activities for Collection PUBLIC",
"updated": "2013-11-01T12:07:44.665Z",
"items": [
{
"kind": "plus#activity",
"etag": "\"Mwea3qudNDf-hWWlPWi3n-YrU1Q/JdSanh1QlMQ72Ubbabsiz2rP4B8\"",
"published": "2013-11-01T12:07:44.665Z",
"updated": "2013-11-01T12:07:44.665Z",
"id": "id",
"url": "https://plus.google.com/userid/posts/bYSPSVjXCXL",
"actor": {
"id": "116100754354787768146",
"displayName": "name",
"url": "https://plus.google.com/userid",
"image": {
"url": "someurl"
}
},
"verb": "post",
"object": {
"objectType": "note",
"content": "",
"url": "https://plus.google.com/userid/posts/bYSPSVjXCXL",
"replies": {
"totalItems": 1,
"selfLink": "https://content.googleapis.com/plus/v1/activities/z13xulwx3qjuxnkii04cjpsqgsjlyp2j23o/comments"
},
}
........
Seems good till now..but,when i use Request URL i.e https://www.googleapis.com/plus/v1/people/myuserid/activities/public?maxResults=5&key={MY_API_KEY} i got something from browser like this
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured"
}
],
"code": 403,
"message": "Access Not Configured"
}
}
where i am going wrong ?! how to get correct response from Browser. ? as i want to parse them and use these data in my Application.
NOTE: Google + API is ON.
Are you making sure that you have replaced {MY_API_KEY} with the API key that you have generated using the Cloud Console?
Are you using the Browser Key? It works OK for me.

YouTube API v3 - List uploaded videos

How do I list the user's uploaded videos in the V3 api?
If you are using the client then Greg's answer is correct. To do the same thing with basic requests you make the following 2 requests:
GET https://www.googleapis.com/youtube/v3/channels
with parameters:
part=contentDetails
mine=true
key={YOUR_API_KEY}
and header:
Authorization: Bearer {Your access token}
From this you will get a JSON response like so:
{
"kind": "youtube#channelListResponse",
"etag": "\"some-string\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"id": "some-id",
"kind": "youtube#channel",
"etag": "\"another-string\"",
"contentDetails": {
"relatedPlaylists": {
"likes": "channel-id-for-your-likes",
"favorites": "channel-id-for-your-favorites",
"uploads": "channel-id-for-your-uploads",
"watchHistory": "channel-id-for-your-watch-history",
"watchLater": "channel-id-for-your-watch-later"
}
}
}
]
}
From this you want to parse out the "uploads" channel-id.
GET https://www.googleapis.com/youtube/v3/playlistItems
with parameters:
part=snippet
maxResults=50
id={YOUR_UPLOAD_PLAYLIST_ID}
key={YOUR_API_KEY}
and headers:
Authorization: Bearer {YOUR_TOKEN}
From this you will receive a JSON response like the following:
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"some-string\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 50
},
"items": [
{
"id": "some-id",
"kind": "youtube#playlistItem",
"etag": "\"another-string\"",
"snippet": {
"publishedAt": "some-date",
"channelId": "the-channel-id",
"title": "video-title",
"thumbnails": {
"default": {
"url": "thumbnail-address"
},
"medium": {
"url": "thumbnail-address"
},
"high": {
"url": "thumbnail-address"
}
},
"playlistId": "upload-playlist-id",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "the-videos-id"
}
}
}
]
}
With this method you should be able to get the info using any language or even just curl. If you want more than the first 50 results, then you will have to do multiple queries using the second request and pass in page requests. More on this can be read at: http://developers.google.com/youtube/v3/docs/playlistItems/list
The first step is getting the channel id for that user. We can do this with request to the Channels service. Here's a JS example.
var request = gapi.client.youtube.channels.list({
// mine: true indicates that we want to retrieve the channel for the authenticated user.
mine: true,
part: 'contentDetails'
});
request.execute(function(response) {
playlistId = response.result.channels[0].contentDetails.uploads;
});
Once we get the playlist id we can use that to query for the list of uploaded videos from the PlaylistItems service.
var request = gapi.client.youtube.playlistItems.list({
id: playlistId,
part: 'snippet',
});
request.execute(function(response) {
// Go through response.result.playlistItems to view list of uploaded videos.
});

Resources