How to update YouTube Channel banner using v3 Data Api? - youtube-api

I'm trying to insert a channel banner using the YouTube v3 Data API. I'm using the .net client library. This documentation calls for a 3 step process.
Upload new banner
Extract new banner url from upload response
Set bannerExternalUrl to extracted url and call channel update.
My problem is with step 2. If I check the returned url is null. I've double check in Fiddler that the json response does not contain a Url property or value.
Anyone have an idea on how do the banner upload? Thanks!
var channelBannerResource = new ChannelBannerResource();
var insertMediaUpload = _serviceV3.ChannelBanners.Insert(channelBannerResource, new FileStream("C:\\banner1.png", FileMode.Open, FileAccess.Read), "image/png");
insertMediaUpload.Oauth_token = _accessToken;
var result = insertMediaUpload.Upload();
//banner Url returns null
var bannerUrl = insertMediaUpload.ResponseBody.Url;

Not too sure but, Check this link out (if you haven't already)
https://developers.google.com/youtube/v3/docs/channelBanners
Your code looks OK on a quick look
One thing to watch out for The image must have a 16:9 aspect ratio and be at least 2120x1192 pixels.
Update
OK, it appears that you haven't called the channels update method. Something like this
Channel updateChannelResponse = youtube.channels()
.update("god knows what parameter(s) here")
Check this link out for more details:
https://developers.google.com/youtube/v3/docs/channels/update
Recon after you call this method the URL should be there...I recon...
Update 2...
Yeah your right, I tried the api explorer but couldn't get that to work either:
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channelBanners.insert?_h=2&resource=%257B%250A++%2522url%2522%253A+%2522http%253A%252F%252Ffr.upphotos.net%252Fwp-content%252Fuploads%252F2013%252F05%252FFerrari-HD-Widescreen-Large.jpg%2522%250A%257D&
But unfortunately get an error response, weird thing is it's complaining about the 'part' parameter but there is none...could this be a bug in the API, can't imagine many people using this functionality
{
"error": {
"errors": [
{
"domain": "youtube.part",
"reason": "unexpectedPart",
"message": "contentDetails",
"locationType": "parameter",
"location": "part"
}
],
"code": 400,
"message": "contentDetails"
}
}
I was expecting this insert to give the URL, fresh out of ideas here.

Related

Getting a list of all Media in Instagram with Graph API

In my code, I have been pulling the list of media in Instagram using the following URL:
https://graph.facebook.com/{app_id}/media?fields=media_url,{..some fields here...}&limit=10000&access_token={my_access_token}
This was working fine and I didn't touch the code for a month. Now suddenly it gives the error:
{
"error": {
"message": "(#100) Tried accessing nonexisting field (media) on node type (Application)",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Aty4vnPpLWfGq9Hj6hQFtZR"
}
}
Nothing in the documentation says that media is no longer available. Graph API version has updated from v14 to v15 since I used it, but the request isn't working on either version.
Access token is fine because other requests are working correctly.
Does anyone have any insights? What alternatives do I have?
I think you are defining an invalid field. Below is a list of fields you can use. Also i suggest you also try instagram account id instead of app_id.
fields=[id,ig_id,media_product_type,media_type,media_url,thumbnail_url,timestamp,
username,like_count,comments_count]
final url:
https://graph.facebook.com/v14.0/{instagram_account_id}/media?fields=id,ig_id,media_product_type,media_type,media_url,thumbnail_url,timestamp,
username,like_count,comments_count&access_token={my_access_token}

YouTube Data API V3 unkownPart "localizations"

I have been trying to fetch all videos from a playlist using YouTube Data API, which worked like a char; next, I wanted to try and filter videos based on languages, so I wanted to try to include the "localizations" part. However, whenever I do, I get a 400 response stating that "localizations" is "unkownPart". From what I could see in the documentation, I should have my GET request structured properly:
`https://youtube.googleapis.com/youtube/v3/playlistItems?part=localizations&part=snippet&maxResults=${limit}&playlistId=${playlistId}&key=${apiKey}`
Error message in postman:
{
"error": {
"code": 400,
"message": "'localizations'",
"errors": [
{
"message": "'localizations'",
"domain": "youtube.part",
"reason": "unknownPart",
"location": "part",
"locationType": "parameter"
}
]
}
}
"localizations" is a direct copy from the documentation. The GET request works fine if I remove it so I'm confident that the problem is either the order or my parameters, or the combinations of parameters in use (though I couldn't find anything about incompatible parameters in the documentation).
Parameters order goes as follows:
localizations
snippet
playlistId
key
EDIT: link to the documentation: https://developers.google.com/youtube/v3/docs/playlists/list
After sending the Issue Report it was discovered that I had been using the wrong API endpoint. Somehow (I can't remember why) I was using the "playlistItem" endpoint which doesn't support "localizations", and needed to shift to using the "playlists" endpoint instead.
Furthermore when using a combination of both "snippet" and "localization", they should be within the same parameter but comma-separated, however, Postman doesn't auto-convert the commas in the parameters to "%2C" and therefore would cause further trouble understanding the requests. Fixing these 2 steps, it now works as intended.

Youtube Data API V3 - Uploading video through PHP code shows error

I've been using following code since a year now but suddenly this errors started appearing.
I'm using PHP Code sample provided in following url
https://developers.google.com/youtube/v3/code_samples/php#upload_a_video
ERROR:
{
"error": {
"errors": [{
"domain": "youtube.thumbnail",
"reason": "videoNotFound",
"message": "The video that you are trying to insert a thumbnail image for cannot be found. Check the value of the requests \u003ccode\u003evideoId\u003c/code\u003e parameter to ensure that it is correct.",
"locationType": "parameter",
"location": "videoId"
}],
"code": 404,
"message": "The video that you are trying to insert a thumbnail image for cannot be found. Check the value of the requests \u003ccode\u003evideoId\u003c/code\u003e parameter to ensure that it is correct."
}
}
I've print statement just before this error catching, and I could see the video ID. And I could see a wiered behavior on my video url.
https://www.youtube.com/watch?v=KV-5aiMDLDg
No comment box, no suggested videos.
Anyone else facing this issue, is there an error/Bug reported recently from Youtube?
I am having the exact same problem. Code has been running fine forever, and now is failing. I added a 20 second delay after the video upload completes, before the thumbnail is set, and it seems to always work now. So it acts like Youtube needs time to digest the video. Would love to hear a better solution though.

Getting status for playlist from Youtube API

I'm building an app that based on user's choice connects to youtube api and get's list of videos of certain playlist.
I would like to make it safe to use and if the status is not 200, make it impossible for the next screen to show.
The JSON result from my request does not return any information on the status other than privacy status (similarly, if I get data for a video not a playlist I get detailed information) :
var urlString = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=500&playlistId=\(playlistId)&key=XXXXX"
"status":{
"privacyStatus":"public"
}
How do I verify that the request for the playlist is valid?
Thanks!
I have not found a reliable way to test the YT api status, so I generally will look for results from the call that should be there. And if they are not there (i.e. empty or '0' ) , then it is normally a failed call.
So [totalResults] and/or [title] as example.
There are two parts here.
You need to determine if the actual HTTP request was successful or not (that is the request to https://googleapis/youtube/v3/[method]?[parameters])
You have a specific requirement where you need to handle cases where there is no data. The response from the API itself will not explicitly provide this to you, instead you need to define what failure means.
With this in mind, you could implement two levels of checks:
Check 1 - HTTP status code
The first level would check the HTTP status code (200 = OK, 400 = Bad Request, etc.).
If your API request returns a status of 200, you can move on to the next level of checks (see Check 2). However, if your API request returns a status of 400, then the request has failed and no further checks are required (or necessary).
Note: If you do get a 400 status, there is some JSON in the response which contains detailed information regarding the error.
{
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "missingRequiredParameter",
"message": "No filter selected. Expected one of: id, playlistId",
"locationType": "parameter",
"location": ""
}
],
"code": 400,
"message": "No filter selected. Expected one of: id, playlistId"
}
}
Check 2 - Data
The second level would check to see if any results have been returned (as it seems possible to have a HTTP status code of 200 and no results).
This has nothing to do with the status of the actual HTTP request itself. Instead you have to check the response to see if the data you application requires is present or not.
With the example of a 200 response below, the items array is empty. So you could say that even though the request was successful, this is a failure condition and not show your next screen.
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"[etag would appear here]\"",
"nextPageToken": "CAAQAA",
"pageInfo": {
"totalResults": 199,
"resultsPerPage": 0
},
"items": [
]
}
Note: The above is an example where the results per page was purposely set to 0.

Simplest way to display upcoming events from a public Google calendar?

I have a public calendar on the site. I need to display upcoming events on the front page.
After spending the whole day on this I am about to give up. Google is disabling older API there is no documentation or anything. I am parsing the RSS feed:
http://www.google.com/calendar/feeds/.../public/basic?futureevents=true
And grabbing feed/entry/update and feed/entry/title from XML. I read somewhere that futureevents will display upcoming events. However I get the list of older events.
Okay, then I tried to use API V3 https://developers.google.com/google-apps/calendar/v3/reference/events/list
Here is the responce I get:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
I jumped through more hoops and installed their ruby code sample as I need this for Rails site.
It sort of worked but it requires user to confirm access to their own calendar. I don't need that. Plus it seems that authentication only valid for a day.
The said calendar is public. It is being displayed in iframe on the site with xml and ical feed. All I need is to parse upcoming events to show them on front page.
What is the way to do it without authorization and other ridiculous stuff?
//This works for me! js:
var request = gapi.client.calendar.events.list({
'calendarId': 'xxx',
'timeMin': (new Date()).toISOString(),
'showDeleted': false,
'singleEvents': true,
'maxResults': 1,
'orderBy': 'startTime'
});
request.execute(function(resp) {}
Use this wizard to create a new API project: https://console.developers.google.com/start/api?id=calendar Then click on "create new key" (choose server key). Then do a request to https://www.googleapis.com/calendar/v3/calendars//events?key={YOUR_API_KEY} replacing the email and api key with your values.

Resources