Issues getting Youtube API WordPress plugin Restricted - youtube-api

I’m still having no luck getting this Youtube API Restricted properly.
Every time I try to give it HTTP referrers Restrictions & add the following Website Restrictions:
https://www.ohiocannabis.com
https://www.ohiocannabis.com/*
I then get the following error in my Youtube video player on my website: http://www.ohiocannabis.com/videos
Sorry, there was a YouTube API error: The referrer https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,status&playlistId=UUkbzQe9G_drgd3QoLmHZNfw&maxResults=15&key=AIzaSyArOPULA9UG52ZQUO7ddZMxrpC6odiFW4I does not match the referrer restrictions configured on your API key. Please use the API Console to update your key restrictions. Please make sure you performed the steps in this video to create and save a proper server API key.
I've also tried using the IP Restriction, the IP for my website is: 107.154.147.253
But when I use that the player gives me the following error:
Sorry, there was a YouTube API error: The calling IP address 50.116.78.101 does not match the IP restrictions configured on the API key. Please use the API Console to update your key restrictions.
So who/what/where is this “Calling IP” coming from that it would have a much different IP than my website domain?
(I unrestricted it so that my videos populate for now, so you may not see that error message on my Videos page)
Any idea on what I’m doing wrong to get this plugin to Restrict & work properly?
Thank you!!
I've tried adding HTTP Restrictions and also IP Restrictions, both with no luck.
I haven't tried any code yet, not sure what to do.
Sorry, there was a YouTube API error: The referrer https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,status&playlistId=UUkbzQe9G_drgd3QoLmHZNfw&maxResults=15&key=AIzaSyArOPULA9UG52ZQUO7ddZMxrpC6odiFW4I does not match the referrer restrictions configured on your API key. Please use the API Console to update your key restrictions. Please make sure you performed the steps in this video to create and save a proper server API key.
Sorry, there was a YouTube API error: The calling IP address 50.116.78.101 does not match the IP restrictions configured on the API key. Please use the API Console to update your key restrictions.

So I think I figured it out, I was adding a double restriction on this API by doing the HTTP and the API Restrictions option at the bottom.
I've removed the HTTP Restriction and just kept the API Restriction enabled to the Youtube Data API v3 and it seems to not be giving me the error any longer and showing all of my videos and google console is showing it is in fact now a Restricted API.
Does this sound like I did it right this time?
Thank you!

Related

How to get Youtube video views by date range

I am trying to get youtube video views by date range and it is working fine with oAuth. But I am using cron script to collect those data through service account, when I try to execute the script it says:
Error calling GET https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DUC88Bq63MDJi9szYPEGfv7YA&start-date=2014-02-01&end-date=2016-06-29&metrics=views:
(400) Invalid query. Query did not conform to the expectations".
Could you please help me anyone to resolve this issue. Thanks in advance.
Using service account is not supported by Youtube Analytics and Reporting API
The service account flow supports server-to-server interactions that do not access user information. However, the YouTube Reporting API and YouTube Analytics API do not support this flow. Since there is no way to link a Service Account to a YouTube account, attempts to authorize requests with this flow will generate an error.
Unfortunately, you need to do OAuth2 to get your report.
Resources you can check for information:
Youtube Analytics API PHP Invalid query. Query did not conform to the expectations
Implement OAuth 2.0 Authorization

YouTube API from V2 to V3 migration

I'm still using old V2 api and now i get https://youtube.com/devicesupport.
My current request is:
https://gdata.youtube.com/feeds/api/users/{username}/uploads?alt=jsonc&max-results=15&v=2
There is no authentication required to make that call
Question:
Any idea how to achieve the same with new Google V3 API? I check documentation but didn't found answer for that.
I had the same problem with V3 api. I think you can't access videos informations without authentication anymore, but you don't need to use an OAuth to get a snippet from some video or search. I was searching a simple solution for my app, because I just want to request title, thumb and descriptions.
The new url will be:
https://www.googleapis.com/youtube/v3/videosid={VIDEO_ID}&part=snippet&key={YOU_API_KEY}
You need to access google developers console, enable youtube api and your public access key - on credentials (API KEY), so they can relate your app to all requests.
And I found this example in PHP if you need to parse JSON result:
http://www.leenooks.com/php/parsing-youtube-v3-json-with-php-examples.html
I'm still don't know all the limitations of V3, I was using V2 too, but maybe for uploads, or more control for youtube accounts you'll have to use OAuth.
I hope this will help you.

Using YouTube API v3 to tell if a channel has a live stream

The goal of my YouTube API call is, given a channelId, to return whether that channel is currently live streaming. This is the call I'm making currently:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={CHANNEL_ID}&eventType=live&type=video&key={YOUR_API_KEY}
While this call is functional, there is a significant delay between the channel starting a live stream and this call returning the stream.
Is there a better call to use in the YouTube v3 API that doesn't require oAuth? The functionality of my app is read-only.
Thanks!
Probably late but still someone else would use it, i found the answer on google api docs:
https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/list
(Scroll to bottom, you can use their onsite api to make calls on the fly)
The call you have to make is:
GET https://www.googleapis.com/youtube/v3/liveBroadcasts?part=id%2Csnippet%2Cstatus&mine=true&broadcastStatus=active&key={YOUR_API_KEY}
(atm, they have an issue wth the status field). You can remove the filter and check the returned results for
{ "status": { "lifeCycleStatus": "live"}}
And as per google docs:
Before you start
You need a Google Account to access the Google Developers Console, request an >API key, and register your application.
Register your application with Google so that it can submit API requests.
After registering your application, select the YouTube Data API as one of the >services that your application uses:
Go to the Developers Console and select the project that you just registered.
Open the API Library in the Google Developers Console. If prompted, select a >project or create a new one. In the list of APIs, make sure the status is ON for >the YouTube Data API v3 and, if you are a YouTube Content Partner, the YouTube >Content ID API.
Calling the Data API
The API request must be authorized by the Google Account that owns the >broadcasting YouTube channel.
You can check this link for generating an access(OAuth 2.0) token: https://developers.google.com/identity/protocols/OAuth2?hl=en
I hope this helps.
I was digging for a "cheaper" way to find if a channel is live to save some API quota. I attempted to use Konstantin's workaround by looking at the {channel/channel_id}/live but this appears to not work anymore.
The channel no longer redirects when a person is live. Instead it runs on that page.
If they have a username URL then /c/ works: https://www.youtube.com/c/USER_NAME/live
If they have don't have a username and use the default like UC4R8DWoMoI7CAwX8_LjQHig, then you need to use https://www.youtube.com/channel/USER_NAME/live
The /search call is rather expensive. If you are only allotted the initial 10k quota points, you'd run out of points after only 100 queries. That may not be a bother for some use cases, but it is nevertheless limited.
Instead, you can use Playwright and do the following:
page.goto("https://YouTube.com/channel/{channel id}/live")
Then check for a redirection which will happen when the channel is live:
const redirect = page.url()
If redirect contains a link to a YouTube video, then you know the channel is live. Otherwise it is not live and will yield a link similar to the one that's passed in to the goto() function.

Youtube API v3 on iOS app. My API key does not work, but somebody else's key does work on same application. Error 403

This might be a direct question for the Youtube team at Google, but I thought of asking here first in case it also helps somebody else in the future.
I am using the simple API key (without OAuth 2.0) on an iOS application. This application is simply returning the list of video ids from a specific playlist id. I am supplying the playlist id as well.
When I use my API key that I received from the youtube/google console, I get an error 403 when making the playlistItems request call.
When using somebody else's key (I actually found it online on an example) the application works.
All I'm really changing is the API key. I am not changing the part or playlist id, and in both cases I am using the same iOS application.
My key has both YouTube Data API v3, and the YouTube Analytics API enabled in the google cloud console, along with other default elements that came enabled with this application in google cloud console.
While this approach works, I don't want to bill somebody else's API key for the requests made from my application, and I would also like to have stats of the API request from my iOS app.
Any suggestions?
Has anyone run into this before?
Thank you.
There is a known problem with bundle ids on console. For now, please don't use bundle id, your app should work fine.
You can track the issue in public issue tracker and put bundleid back, once it's fixed. https://code.google.com/p/gdata-issues/issues/detail?id=5770

Google Places API: iOS key: Request Denied [duplicate]

I'm trying to make an Autocomplete field which should fetch cities as the user types, by using the Google Places API as described in this tutorial:
https://developers.google.com/places/training/autocomplete-android
You've probably found this question around many times before as I did, but none of the answers helped me. Here are the things you should know:
The URL is
https://maps.googleapis.com/maps/api/place/autocomplete/json?sensor=false&key=myKey&components=country:ro&input=whatTheUserTypes
Please don't reply by saying you replaced the API key with your own and it worked - the API key which goes there must be Android specific and won't work from a browser.
So did I make the Android API key using the SHA1 fingerprint obtained from the keystore I signed the app with.
I turned on Maps and Places APIs from the console.
The quota isn't exceeded.
All those and it still gives me REQUEST_DENIED
What I didn't mention is that I have O2Auth activated - does that change anything? Shouldn't it be as simple as putting the API key in the app?
Thanks!
Although this has been answered, I think the community could do better.
I was tearing my hair out about this, it just didn't make sense to me.. I was making an iOS/Android App, so I made an iOS/Android Key...
Wrong.
With Google's Places API, your bundle identifier isn't even considered.
What you really want to do is this:
(I'm using the new User Interface)
1. Log into https://cloud.google.com/console#/project
Select your Project Name, then go into API's & Auth > APIs
Make sure you have Places API Turned on. This is the only thing that needs to be turned on for Places-API to work.
2. Go into Credentials
Click CREATE NEW KEY under Public API Access
3. Select BROWSER KEY
4. Click Create, Nothing Else
Leave the HTTP Refer box empty.
5. Use the Key Generated here
This key will allow ANY user from any device access to the API via your Developer login.
You can try it out here: (Be sure to replace YOUR_KEY_HERE with your generated Key)
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Food%20Sh&sensor=false&radius=500&location=0,0&key=YOUR_KEY_HERE
6. Enjoy
Now you can use that URL above in your Android/iOS device.
The Google Places API does not currently support Android or iOS keys generated from the Google APIs Console. Only Server and Browser keys are currently supported.
If you would like to request this support, please file a Places API - Feature Request.
https://developers.google.com/places/training/autocomplete-android
Storing your API key
Although the above code demonstrates how to communicate directly
between an Android app and the Places Autocomplete service, you should
not store your Places API key with your app.
You should therefore build a web application that stores your API key
and proxies the Places API services. In order to secure communication
between your Android app and the proxy web service, you should require
user authentication to your proxy web service. Your Android app can
securely store user credentials and pass them to your web service, or
the user can log into your web app via an Android WebView.
For the latter approach, your web app should create and return a user
authentication token to your Android app, and your Android app should
subsequently pass this token to your proxy web service.
Go to google cloud platform console>Credentials click on edit by selected your YOUR_API_KEY>Application restrictions > select none option>save thats it.
If you select the android apps option from Application restrictions then google deny the place API with exception REQUEST_DENIED.
In Google dev console, you should be able to find both "Places API" and "Places API for Android"
Make sure to use "Places API for Android"
For some reason, "Places API for Android" is hidden in the API list, but can be accessed using search.
I had the same issue , I fix it by leaving
Accept requests from these HTTP referrers (web sites) (Optional)
in browser key Empty
I am still new, so I cannot comment, but to shed some light on Moe's answer, I resolved some similar Google Maps API issues regarding URL queries (for directions, using Volley) with the following steps:
Get Android API Key (including Google Maps Directions API in my case).
Get "Server" API Key (which seems to be created by using a key restriction of "HTTP referrers" these days - really, it's just used to issue URL queries through HTTP).
Store the Android API key as a meta-data tag in the application tag in AndroidManifest.xml with android:name="com.google.android.maps.v2.API_KEY" and android:value as your key. This is used for direct interaction with the Maps API (minus URL queries).
Use the server API key whenever issuing URL queries.
I am not sure if this also applies to URL queries for the Places API, if you only need the server API key, or if there is a better solution, but this worked for me.
I imagine that it works with just the first key - the one not restricted to Android.
Inside Google Cloud Console type Places and Activate it. Create an API Key and insert it onto your Android Studio App as you would do normally. That`s it.
I had the same problem. For me the key was to enable billing on project. I am still using "Applications for Android" restrictions. After setting up the payment method, Places Api started working.
Prior to using the Places SDK for Android, do the following:
Follow the Get an API Key guide to get, add, and restrict an API key.
Enable billing on each of your projects.
Enable the Places API for each of your projects.
See it there.
Be sure also to check out the billing plans for the Google Places API as it is not free!

Resources