Context:
I'm building a website using Symfony2 (php) and I have already implemented a social(google) login function (through HWIOAuthBundle) that allows users to:
- register a new account using their own google account
- link a google account to an existing non-social account
As a result, in my database the users table already has a google_id field.
What I want to do:
Users must be able to submit youtube links of their own videos. These links will be saved in the database BUT first I need to verify that the video BELONGS(IS OWNED) to the user that is submitting the link. In other words: users CAN NOT submit videos uploaded by someone else.
I plan on using the Youtube API (php) that you can find on the google developers website.
Question(s):
How can I verify this condition? Can I use the Google Id that I already have in my users table? Or do I need to create a new youtube_id field because the id is different from the google_id? What api function/method should I call to verify the video ownership?
Ideas?
Try to check them by v3/videos - https://developers.google.com/youtube/v3/docs/videos/list
if you use "part=snippet"
you will see channel info in items->snippet->channelId and items->snippet->channelTitle
For example for https://www.youtube.com/watch?v=YVe2THgSDxc load
https://www.googleapis.com/youtube/v3/videos?id=YVe2THgSDxc&part=snippet&key=[YOUR_API_KEY]
You will get
{
"kind": "youtube#videoListResponse",
"etag": "*******",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#video",
"etag": "*******",
"id": "YVe2THgSDxc",
"snippet": {
"publishedAt": "2018-01-22T15:47:46.000Z",
"channelId": "UCiP6wD_tYlYLYh3agzbByWQ",
"title": "30 Minute HIIT Cardio*******",
"description": "Full info for thi*******.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/YVe2THgSDxc/default.jpg",
"width": 120,
"height": 90
},
*******
},
"channelTitle": "FitnessBlender",
"tags": [
"fitness blender",
"fitness",
"blender",
"workout",
"workout videos",
"hiit workout",
"cardio workout",
"hiit cardio",
"cardio at home",
"hiit at home",
"at home hiit",
"at home workouts",
"free workout videos",
"hiit cardio workout",
"strength",
"strength training",
"strength training workout",
"dumbbell workout",
"at home strength training",
"strength and hiit",
"hiit and strength",
"lower body workout",
"butt workout",
"thigh workout",
"butt and thigh workout",
"fat burning workout",
"muscle building workout"
],
"categoryId": "26",
"liveBroadcastContent": "none",
"localized": {
"title": "30 Minute HIIT Ca*******",
"description": "Full info for this *******"
}
}
}
]
}
So if you have users's channelID or channelName you can compare it with video's channelID or channelName.
If you have user's name but haven't his channel list you can get it by v3/channels
For example this gets channel list for user "popsugartvfit"
https://www.googleapis.com/youtube/v3/channels?&part=contentDetails&forUsername=popsugartvfit&key=[YOUR_API_KEY]
You will get
{
"kind": "youtube#channelListResponse",
"etag": "*****",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#channel",
"etag": "*******",
"id": "UCBINFWq52ShSgUFEoynfSwg",
"contentDetails": {
"relatedPlaylists": {
"uploads": "UUBINFWq52ShSgUFEoynfSwg",
"watchHistory": "HL",
"watchLater": "WL"
}
}
}
]
}
And use if for validation
Related
If I make a curl request for this URL:
https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&id=UC_x5XG1OVP6uZZ5FSM9Ttw&key=...
I'll get the output as:
{
"kind": "youtube#channelListResponse",
"etag": "J801W-IQ15sDpy3GjDfjlUgoVxA",
"pageInfo": {
"resultsPerPage": 0
}
}
Does this mean that the YouTube channel doesn't exist?
I don't get any error; how to find whether this is a valid channel or not?
Likewise, I want the list of videos of a given channel. If I make a curl request using this URL:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCIJIhBwx4XjNUtQGZTGSVnA&maxResults=20&order=date&key=[YOUR_API_KEY]
I'll get the output as:
{
"kind": "youtube#searchListResponse",
"etag": "q5r0QewUnrg2C7BdwuxbJxb9b8c",
"regionCode": "IN",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 20
},
"items": []
}
This is a valid channel ID, but I get an empty result, not an error; how to know the search is valid or not?
Question no. 1
For what concerns your first question:
Given a channel ID -- $CHANNEL_ID --, test whether the respective channel exists or not.
I would recommend invoking curl on the following URL:
https://www.googleapis.com/youtube/v3/channels?part=id&fields=items/id&id=$CHANNEL_ID&key=$APP_KEY
Note that invoking the Channels.list endpoint through the URL above -- which contains the parameters part=id and fields=items/id -- will return only the channel's ID.
Although not documented explicitly, tests show that you'll get back from the endpoint the ID you passed on to it, if and only if that channel does actually exist.
For example, in case of your channel ID above -- UC_x5XG1OVP6uZZ5FSM9Ttw --, the API response is trivially empty:
{}
becase this channel does not exist (only have to click on this link to see that yourself).
On the other hand, in case of NBCNews' channel -- UCeY0bbntWzzVIaj2z3QigXg -- the response is:
{
"items": [
{
"id": "UCeY0bbntWzzVIaj2z3QigXg"
}
]
}
showing that indeed this channel is live and kicking.
Question no. 2
For what concerns the second question of your post:
Given a channel by its ID $CHANNEL_ID, do list the videos of that channel.
I recommend you to consult the answer I gave recently to this very question.
In terms of curl, you'll have to invoke the following URL:
https://www.googleapis.com/youtube/v3/channels?part=contentDetails&fields=items/contentDetails/relatedPlaylists/uploads&id=$CHANNEL_ID&key=$APP_KEY
for to obtain that channel's uploads playlist ID. For example, in the case of NBCNews' channel, the API response is:
{
"items": [
{
"contentDetails": {
"relatedPlaylists": {
"uploads": "UUeY0bbntWzzVIaj2z3QigXg"
}
}
}
]
}
Then take out that ID from the JSON response as $PLAYLIST_ID and invoke curl on the following URL repeatedly, implementing pagination:
https://www.googleapis.com/youtube/v3/playlistItems?part=id,snippet,contentDetails,status&maxResults=50&playlistId=$PLAYLIST_ID&key=$APP_KEY.
In case of NBCNews' uploads playlist, the output of the first page would look like:
{
"kind": "youtube#playlistItemListResponse",
"etag": "5DW9uT73DWmJtDoJ-rSw3AqHKpc",
"nextPageToken": "CAUQAA",
"items": [
{
"kind": "youtube#playlistItem",
"etag": "_X3LvLIRvEBM3RetizOGtB03ja0",
"id": "VVVlWTBiYm50V3p6VklhajJ6M1FpZ1hnLjE5NjU4N0NGQkY5M0M3MjI=",
"snippet": {
"publishedAt": "2020-09-12T06:11:59Z",
"channelId": "UCeY0bbntWzzVIaj2z3QigXg",
"title": "Watch NBC News NOW Live - September 11",
"description": "NBC News NOW is live, reporting breaking news and ...",
"thumbnails": {
...
},
"channelTitle": "NBC News",
"playlistId": "UUeY0bbntWzzVIaj2z3QigXg",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "yXO2hQXC5Dw"
}
},
"contentDetails": {
"videoId": "yXO2hQXC5Dw",
"videoPublishedAt": "2020-09-12T06:11:59Z"
},
"status": {
"privacyStatus": "public"
}
},
{
"kind": "youtube#playlistItem",
"etag": "PGyhZonOjiRzqHu7DKDPk6gcMTo",
"id": "VVVlWTBiYm50V3p6VklhajJ6M1FpZ1hnLjY2RTJFNDA4MDA0NDREQTU=",
"snippet": {
"publishedAt": "2020-09-12T02:48:48Z",
"channelId": "UCeY0bbntWzzVIaj2z3QigXg",
"title": "Gaza Sees Spike In Coronavirus Cases, Severe Shortage Of Supplies | NBC News NOW",
"description": "NBC News’ Kelly Cobiella reports on the surge in Gaza ...",
"thumbnails": {
...
},
"channelTitle": "NBC News",
"playlistId": "UUeY0bbntWzzVIaj2z3QigXg",
"position": 1,
"resourceId": {
"kind": "youtube#video",
"videoId": "I0lHV0ZVPAs"
}
},
"contentDetails": {
"videoId": "I0lHV0ZVPAs",
"videoPublishedAt": "2020-09-12T02:48:48Z"
},
"status": {
"privacyStatus": "public"
}
},
...
],
"pageInfo": {
"totalResults": 20000,
"resultsPerPage": 50
}
}
Do notice the property nextPageToken within the JSON response text above; the value of this property -- CAUQAA -- would have to be passed to the second invocation of the endpoint as the parameter pageToken=CAUQAA added to the initial URL above.
For to obtain the n-th page, you'll extract the value of nextPageToken from the n-1-th page, for to pass that value to the the n-th URL as pageToken=....
There is no request in the API that will tell you 100% if a channel exits or not.
Even doing a do a video search for the channel wont help you as. If it exists then it would return the videos for that channel, if not then you get back 0 videos.
request
curl \
'https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCMPpVtxOI8RtfurfvCcxgyA&order=date&key=[YOUR_API_KEY]' \
--header 'Accept: application/json' \
--compressed
response
{
"kind": "youtube#searchListResponse",
"etag": "oaf4zpPSG6Ho_cSxZedNhuVhjkw",
"nextPageToken": "CAUQAA",
"regionCode": "DK",
"pageInfo": {
"totalResults": 1721,
"resultsPerPage": 5
},
"items": [
no channel
In the event no channel exists the above code will return total results of 0
{
"kind": "youtube#searchListResponse",
"etag": "opQHhlM-mBA_i0h80B_gmHdKgCE",
"regionCode": "DK",
"pageInfo": {
"totalResults": 0,
"resultsPerPage": 5
},
"items": []
}
Another option
Another option would be to not use the API at all. Just make a call to against YouTube itself.
If you load this page it loads the actual channel https://www.youtube.com/c/NBCNews However if you try to load https://www.youtube.com/c/lafjdajdskfadkfj it redirects you to https://www.youtube.com/error?src=404 i would think that would be something simple to detect.
I am firing a query regarding events created by a particular user in Facebook.
Want to import the same in SQL.
Following is the result of FQL
{
"data": [
{
"name": "Demo Event",
"pic": "https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v2/yi/r/zSnTif5Rf_V.png",
"start_time": "2013-07-07T00:00:00+0530",
"end_time": "2013-08-29T03:00:00+0530",
"location": "Kulraj Broadway",
"description": "Pls ignore"
},
{
"name": "Demo Event Pls ignore",
"pic": "https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v2/yi/r/zSnTif5Rf_V.png",
"start_time": "2013-06-24T18:10:00+0530",
"end_time": "2013-06-27T21:10:00+0530",
"location": "NCPA Theatres",
"description": "NM NM "
}
]
}
I need to know how to fire FQL in standalone app,store all this data in my SQL.
Help me out to implement the same.
Thanks!
Recently, our team is going to develop mobile(iphone, android platforms) applications for our existing website, let user can use the application to more easy to read our content via the application.
But our team have different views in JSON schema of the API return, below are the sample response.
Schema type 1:
{
"success": 1,
"response": {
"threads": [
{
"thread_id": 9999,
"title": "Topic haha",
"content": "blah blah blah",
"category": {
"category_id": 100,
"category_name": "Chat Room",
"category_permalink": "http://sample.com/category/100"
},
"user": {
"user_id": 1,
"name": "Hello World",
"email": "helloworld#hello.com",
"user_permalink": "http://sample.com/user/Hello_World"
},
"post_ts": "2012-12-01 18:16:00T0800"
},
{
"thread_id": 9998,
"title": "asdasdsad ",
"content": "dsfdsfdsfds dsfdsf ds",
"category": {
"category_id": 101,
"category_name": "Chat Room 2",
"category_permalink": "http://sample.com/category/101"
},
"user": {
"user_id": 2,
"name": "Hello baby",
"email": "hellobaby#hello.com",
"user_permalink": "http://sample.com/user/2"
},
"post_ts": "2012-12-01 18:15:00T0800"
}
]
}
}
Schema type 2:
{
"success": 1,
"response": {
"threads": [
{
"thread_id": 9999,
"title": "Topic haha",
"content": "blah blah blah",
"category": 100,
"user": 1,
"post_ts": "2012-12-01 18:16:00T0800"
},
{
"thread_id": 9998,
"title": "asdasdsad ",
"content": "dsfdsfdsfds dsfdsf ds",
"category": 101,
"user": 2,
"post_ts": "2012-12-01 18:15:00T0800"
}
],
"category": [
{
"category_id": 100,
"category_name": "Chat Room",
"category_permalink": "http://sample.com/category/100"
},
{
"category_id": 101,
"category_name": "Chat Room 2",
"category_permalink": "http://sample.com/category/101"
}
],
"user": [
{
"user_id": 1,
"name": "Hello World",
"email": "helloworld#hello.com",
"user_permalink": "http://sample.com/user/Hello_World"
},
{
"user_id": 2,
"name": "Hello baby",
"email": "hellobaby#hello.com",
"user_permalink": "http://sample.com/user/Hello_baby"
}
]
}
}
Some Developers claim that if using schema type 2,
can reduce data size if the category & user entities comes too much duplicated. it does really reduce at least 20~40% size of response plain text.
once if the data size come less, in parsing it to JSON object, the memory get less
categoey & user can be store in hash-map, easy to reuse
reduce the overhead on retrieving data
I have no idea on it if schema type 2 does really enhanced. Because I read so many API documentation, never seen this type of schema design. For me, it looks like a relational database. So I have few questions, because I have no experience on designing a web services API.
Does it against API design principle (Easy to read, Easy to use) ?
Does it really get faster and get less memory resource on parsing on IOS / Android platform?
Does it can reduce the overhead between client & server?
Thanks you.
When I do such an application for android, I parse JSON just one and put it in database. Later I'm using ContentProvider to access it. In Your case You could use 2nd schema but without user, category part. Use lazy loading instead but it will be good solution just in case categories and users repeat often.
Facebook Page: http://facebook.com/getwellgabby/events/ currently has 8 events on it. I can see them. Non-admins can see them and can join them.
However, when I make calls via the Graph API or FQL, only 4 future events are returned. Results can be seen here: http://getwellgabby.org/events?raw=1 (Scroll to bottom for raw response.)
FQL Query is:
SELECT eid, name, start_time, end_time, location, venue, description
FROM event WHERE eid IN ( SELECT eid FROM event_member WHERE uid = 213367312037345 ) AND end_time > now()
ORDER BY end_time asc
Inspecting individual event IDs returned via Graph API shows no difference between these events. However, when editing them via the front end, they display in different dialogs.
Two sample events follow. Both were created by the same page admin approx. 24 hours apart. The first event displays properly via an API/FQL call. The second does not. From the front end, the second event displays differently than the first.
Data below was returned using the FB Graph API Expplorer Tool using an Access Token with "create_event" privileges.
Reports Correctly:
{
"id": "344143808978921",
"owner": {
"name": "Get Well Gabby",
"category": "Non-profit organization",
"id": "213367312037345"
},
"name": "Get Well Gabby Day With The Reading Phillies",
"description": "Please join [truncated...]",
"start_time": "2012-06-10T13:30:00",
"end_time": "2012-06-10T16:30:00",
"location": "FirstEnergy Stadium",
"venue": {
"street": "1900 Centre Ave.",
"city": "Reading",
"state": "Pennsylvania",
"country": "United States",
"latitude": 40.357,
"longitude": -75.91434,
"id": "223424611014786"
},
"privacy": "OPEN",
"updated_time": "2012-04-25T14:22:57+0000",
"type": "event"
}
Does not report correctly:
{
"id": "128748077259225",
"owner": {
"name": "Get Well Gabby",
"category": "Non-profit organization",
"id": "213367312037345"
},
"name": "Get Well Gabby Day With The Wilmington Blue Rocks",
"description": "Get Well Gabby Day With [truncated...]",
"start_time": "2012-07-29T13:35:00",
"end_time": "2012-07-29T16:35:00",
"timezone": "America/New_York",
"location": "Frawley Stadium",
"venue": {
"id": "148306638522325"
},
"privacy": "OPEN",
"updated_time": "2012-04-25T18:11:35+0000",
"type": "event"
}
Note, front end dialog for the event that does not report correctly will not accept additional venue information.
You can use since and until to increase the scope of your query.
here is an example using graph api explorer and search events (shows future events)
https://developers.facebook.com/tools/explorer/135669679827333/?method=GET&path=search%3Ftype%3Devent%26q%3Da%26limit%3D100%26since%3Dnow%26until%3Dnext%20year
171535666239724/events?since=2010&until=now // all events since 2010 until now
171535666239724/events?since=now&until=2013 // all events from now until 2013
for graph api requests:
until, since (a unix timestamp or any date accepted by strtotime http://php.net/manual/en/function.strtotime.php): https://graph.facebook.com/search?until=yesterday&q=orange
The issue seems to have resolved itself for now. Thanks if someone following this issue did something at Facebook.
How can we identity the date on which someone liked my page.
is there any way where we can identify the date on which someone liked my page ?
No. You can't even get a list of people that like your page, so you can't get a date they liked it. The only information you can get is how many people like it.
You can view a chart of how many people liked your page over time at Facebook Insights.
Well no, You can make a graph call to the statuses and feeds of a user with valid access_token to get the id and name of the people who liked the post.. The timestamp can be found for the comments though ..
{
"id": "257821xxxxxxx",
"from": {
"name": "Maxxxxxx",
"id": "100xxxxxx"
},
"message": "incredible ..",
"updated_time": "2011-09-15T11:21:15+0000",
"likes": {
"data": [
{
"id": "6xxxxxx6",
"name": "Axxxxxxxxxa"
}
]
},
"comments": {
"data": [
{
"id": "257xxxxxxxxxxxx904",
"from": {
"name": "Maxxxxxxxxxxal",
"id": "1xxxxxxxxxxxxxx"
},
"message": "htxxxxxxxxxxxxxxxxxxxxxxxxxx",
"can_remove": true,
"created_time": "2011-09-15T11:22:06+0000"
}
]
}
}