Getting YouTube Channel Views - php

I'm trying to get the channel views of the logged in user, through googles' oauth2. I'm able to get name and email via this url: https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=[GENERATED TOKEN]
Now, I'm having a hard time finding any information about how I would go about getting the users channel views. I know you can get a list of videos and such, but how would I do this?
Is there an equivalent to the link I posted above? :)

You can do a channels->list
GET https://www.googleapis.com/youtube/v3/channels?part=contentDetails&mine=true&key={YOUR_API_KEY}
In response contentDetails.relatedPlaylists.watchHistory will have the playlist id of watched videos. You can iterate through that playlist with playlistItems->list.
GET https://www.googleapis.com/youtube/v3/playlistItems?part=snippet%2C+contentDetails&id={PLAYLIST_ID}&key={YOUR_API_KEY}

Related

Get my posts on facebook manage page

I need get ME posts in one of my manage pages, with the new version of facebook sdk.
Example:
I'm manage on Page A, and add a post in my name Adexe Rivera, and in this page there are a lot of posts. So I want to filter only posts by Adexe Rivera.
I know for get posts on pages it's necesary /page/feed, but I need add the filter from user.
I tried with Graph Api Explorer, with this FQL:
SELECT source_id, actor_id, post_id, target_id, message FROM stream WHERE source_id = "PAGE_ID" AND actor_id = "MY_ID"
and get the information that I'm searching.
But I know that since v2.0 FQL not works for sdk, so that I need it's make the same like FQL works in this version of graph
I already tried what documentation said, but not get my posts.
A user access token is required to retrieve posts visible to that person.
Thanks in advance
Filtering is not possible, you can only use the existing endpoints and filter on your own after getting the entries. There are several different endpoints, make sure you are using the correct one. They are all documented very well: https://developers.facebook.com/docs/graph-api/reference/v2.4/page/feed
Also, an App Access Token should be enough to get access to the endpoints if it´s a public post on a non-restricted Page:
An access token is required to view publicly shared posts.
If you don´t know about Access Tokens, read those articles:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
Finally, it is not possible to use FQL giving me the expected result, so getting the "from" field in the /PAGEID/feed endpoint, and filtering the results, I get what I wanted.
Thanks for your answers and for their penalties, I have spent several days trying to maximize the performance of the SDK facebook.
Cheers

How can I get related videos with php on youtube api?

I want to get related videos on Youtube when user enters the video id on my system. But system will work like this:
User will enter video id
System will find related videos of the video that user entered.
After that, system will choose one of the related videos and start to get that video's related vids list.
System will repeat this for 10 times.
And will show to user last video.
So, my problem is getting first video's related video and after last video's, after last video's etc... And my aim is try to find the journey from first video to last video.
How can I do this?
You can do this via search->list method specifying relatedToVideoId.
You can use PHP API client.
Here is a similar sample. https://github.com/youtube/api-samples/blob/master/php/search.php

YouTube Api (V2.0 or 3.0) get channel info given channel url

I've to get 3 simple information from a youtube channel given the channel url.
Channel url(example): http://www.youtube.com/user/autocar
Needed info: Total videos, subscribers and total views.
I thought that those information should be simple to retrieve thanks to the API. Instead I'm going crazy trying to understand the Google Data documentation.
I'm working with PHP, so I suppose that I could use the php google client. But on the other side I'm pretty sure that to retrieve those simple information I can avoid to use the full library... anyway, someone knows how to get those data?
First, you need to find the channel id, some URLs come with channel id, some with username.
Great documentation here.
Basically, if it's a
Channel id, you already have it.
Username, channels.list(part="id", forUsername="username")
Once you have the channel id, you'll do a channel->list request to get all these details.
Response will have all the details.
Give it a try with API explorer with a channel id or username.
PHP Samples to get you started fast.
One way to get all the things you have requested is to search for channel
For instance
$channel_query = "channel_name";
$yt_url = "https://gdata.youtube.com/feeds/api/channels?q=".$channel_query."&alt=json&v=2";
$data = file_get_contents($yt_url);
echo "<pre>"; print_r(json_decode($data)); echo "</pre>";
After you get the feed, you would need to loop through the channel entries and match your channel. Best way of doing that is using your channel ID.

Is there any way to get the owner of a YouTube video via the 3.0 api?

I'm looking for some sort of username or uid field associated with the video (so I can confirm that a video someone claims to own is really owned by that person). I'd expect it to be in "snippet", but it's not there. I guess I could go through the channels interface and the playlist of the user, but I'd think the video's owner is something that would be available through the videos api itself. Any ideas?
snippet is correct, and the field is called "channelTitle"
Screenshot:
Yes, video owner is not returned from Videos resource.
You can do Channels->list
from relatedPlaylist.uploads.
Iterate through PlaylisItems to match.
Use Channels.list
snippet.channelTitle will give you the name of the Channel.
contentDetails.googlePlusUserId might give you more info, but only if the user has associated a Google+ account with with the YouTube channel.
Make sure to specify part='snippet,contentDetails'
There is also a lot of information in:
http://www.youtube.com/get_video_info?video_id=your-video-id, including a field called content_owner_name. It requires some parsing to extract the info.

How to get the media ID using Instagram's API

I've been trying to retrieve the users who have commented on a picture at Instagram. The issue I'm facing is that you require the media ID of the image to use in the api endpoint. I'm using this code to get the media ID of the image:
$api = file_get_contents("http://api.instagram.com/oembed?url=https://www.instagram.com/p/BBHOUQyuS3T/?taken-by=kimkardashian");
$apiObj = json_decode($api,true);
$media_id = $apiObj['media_id'];
print_r($media_id);
which gives me a media ID of 1172969193024859603_18428658.
When I input this into my api request like this:
$api = file_get_contents("http://api.instagram.com/v1/media/".$media_id."/comments?access_token=".$access_token);
with my particular access_token, I get a 400 error code. When I go direct to the page url, it says:
Invalid media id.
Has anyone else had this problem before? If so how did you solve it?
Another puzzling part of this is that, after looking around the Stackoverflow for a while, I found a couple ways of translating the shortcode for the picture into the media ID.
One of them is nodejs module here which gives me a media ID for the image of 1172969193024859603, so like the original but without the bit after the underscore. Both ID's give me the same error.
I've been at this for hours and it's driving me mad! Please help.
Thats the expected response in sandbox mode if you are trying to access a user's media that is not in your sandbox authorized user list.
https://www.instagram.com/developer/sandbox/
Data is restricted to sandbox users and the 20 most recent media from
each sandbox user
Add the user who's photo u want to access to your sandbox users, then you will get a valid API response for media
The media_id 1172969193024859603_18428658 and 1172969193024859603 are the same the part after underscore is the media owner's user_id, both are valid for media_id

Categories