Get video views for Instagram posts error in Graph Api - instagram-graph-api

I am using the graph api explorer to create a query to get insights data about my Instagram page. It looks like this and it works fine. Some posts are photos some are videos.
IG id/media?fields=timestamp,caption,permalink,media_type,like_count,comments_count,insights.metric(reach,impressions,saved,engagement)
When i add the video_views metric though i get an error
"message": "(#100) Can not show video views count for non video media"
Anyone know what am i doing wrong? I just want to get the video views if the post is a video.

Probably too late, but if you call 'video_views' on an IMAGE media, it will give you this error.
You must handle the IMAGE and VIDEO media separately (i mean with separate fields)
Something like : (pseudo code)
if(post_type == 'VIDEO'):
fields for video ...
else:
fields for image ...

Related

How can I exclude shorts from YouTube API Data v3

I currently use something like https://www.googleapis.com/youtube/v3/search?part=id&order=date&channelId=CHANNELID&maxResults=1&type=video&key=KEY and I want to be able to retrieve only the latest video and to totally exclude shorts.
How can I achieve this? 🤔
The Youtube search method
Will allow you to search for things like keyword, location, events, your own videos and related videos.
There is no way to filter or limit videos returned. Your only hope would be to sort them out locally when you get the results.
You may want to add a feature request here there is this one but it's really old Search API: More flexible/logical videoDuration requests
(sorry its my 1st time answering at stackoverflow, so might not be descriptive)
if you you use youtube serch method
then you'll realise that shorts description are assigned as empty string "" where as the videos have some description . so with an if condition like below can slove your problem (js)
if(!(video.snippet.description == ""))

youtube v3 api : get all live streaming playlist ids of a channel

I have two "Live streaming/live broadcast saved playlists" in following youtube channel --> https://www.youtube.com/user/swaminarayanlive.
I am trying to retrieve all the "live streaming / live broadcast playlists" of a channel using new youtube v3 api by using the below link-->
https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCBkNpeyvBO2TdPGVC_PsPUA&key={YOUR_API_KEY}
here i can get the info of playlists which are not live streams or live broadcast. and not able to get the same for the live one.
Please help me how can i get that for live one using youtube v3 api
I was researching another issue with the API when finding this, and when I saw that this was never resolved, I decided to look into it. It turns out that this is related to that other issue.
The YouTube API v3 lacks support for saved playlists. The channel swaminarayanlive did not create the playlists, only saved them from the channel BhujMandir.
The workaround in your case would be to retrieve the playlists of BhujMandir and extract the response snippets with "title" parameters containing the word "Live".
You would need to go through the pages and search each one for this, since there is a limit to how many results an API response can show at once. Currently it's 50.
So, you would use the following to get the first page of playlistItems:
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCVItNtUctAknegvmYcMhUQg&maxResults=50&key={YOUR_API_KEY}
This will return an API response containing the properties "kind" (which will have the value "youtube#playlistListResponse") and "etag". If there are more than 50 results, there will also be a "nextPageToken" property. (On a page that is not the first, there would also be a "prevPageToken" property.)
After these properties, there are two blocks. One called "pageInfo", containing info about how many results (playlists) there are and how many are shown per page, and one block called "items", containing the resulting playlistItems.
You would look through the items block for any playlistItem with a title property (which is a string) containing the substring "Live" and get the id properties of those. You would then look on the next page by using the nextPageToken's value in a new HTTP request, like so:
GET https://www.googleapis.com/youtube/v3/playlists?part=snippet&channelId=UCVItNtUctAknegvmYcMhUQg&maxResults=50&pageToken=[nextPageToken_value_here]&key={YOUR_API_KEY}
As of now, the two playlists you're looking for are on the pages with tokens CJYBEAA and CMgBEAA.
I think that where is the {YOUR_API_KEY} you should change this code and insert the name of your application program interface

YouTube videos in Orchard CMS

I have a medialibrarypickerfield, I've added a youtube video to it.
How can I get access to the YouTube video URL in an alternate at the following level:
MediaLibraryPicker-ContentType-VideoFieldName.cshtml
I've tried
var field = (MediaLibraryPickerField) Model.ContentField;
var contents = field.MediaParts;
to gain access to each MediaPart/video but when I iterate through the MediaParts, the MediaUrl is null. I know this has something to do with the OEmbedPart but I don't know how to access this.
Extremely frustrating so far. An otherwise very simple task outside of Orchard to store and retrieve URLs.
To access the oEmbed part, just do As<OEmbedPart>() on the media part. You can then access the URL for the video by using the Source property of the part. You can also access a number of properties that are provided by the oEmbed site (YouTube in your case). Those properties can be accessed using the indexer on the part.
For example, part["html"] will give you the html code to embed in your page to render the video player:
#Html.Raw(part["html"])
There is also a "thumbnail" or a "thumbnail_url" property (depending on provider) that will give you the url of a thumbnail image. You can look at the whole blob of XML underlying that in the Framework_ContentItemRecord table's Data column. There is also a width and a height for example.

How can you detect if a youtube video does not have a thumbnail and only uses the default image?

I'm using the YouTube API to retrieve videos but I would like to exclude results which are using the default (gray) image as a thumbnail. Being that the uploader did not select a thumbnail?
What would be the best method to do this? As I don't think there is a flag in the data to reflect this.
I'm using v3 of the youtube api.
Thanks.
On a recent project, I found a hacky but useful way to get relevant thumbnails for each video from the YouTube API.
Of the thumbnails each video record returns, it appears that the fourth thumbnail in the JSON is reliably an identifying frame of the video.
Below, in my fetch_movie_history method, I save the fourth movie thumbnail's url to my movie record so that I can display it later.
def fetch_movie_history
watch_history = self.youtube_client.watch_history
watch_history.videos.each do |video|
movie = Movie.find_or_create_by(unique_id: video.unique_id)
movie.title = video.title
movie.description = video.description
movie.url = video.player_url
movie.thumbnail = video.thumbnails[3].url
movie.save
self.movies << movie
end
end
This is an example screenshot (before styling) of a thumbnail I used on my page:
The description at the bottom is from the video record returned by the API, so you can see it matches up nicely with the thumbnail.
Hope this helps! Best of luck.
I found another solution. I implemented a node service to read the image headers and compare the size to the size of a "no-image" image, thus removing the record when found from my database.

Tags (keywords) are missing from the Youtube API video feed when using category search

When I make an authorized call for Youtube videos, I get all the tags/keywords in the feed.
http://gdata.youtube.com/feeds/api/users/default/uploads?alt=jsonc&v=2
However, if I want to filter this result by a single keyword/category, the tags are not returned by the API. Example, I want to reduce the number of videos in the feed by tag "English"/"French".
http://gdata.youtube.com/feeds/api/users/default/uploads/-/English?alt=jsonc&v=2
Is this expected behavior or a bug?
It's expected behavior; this blog post explains how your second request is going against the search index, which will never return keywords/tags in the response.

Resources