Issue with Youtube API key

Posted in: Newspaper
Post count: 1

Hi,
We were trying to set up a youtube video as a background on our slider as described here:
https://tagdiv.com/videos-design-trends-newspaper-theme/

We ran into an issue with the Google API Referer Key restrictions and we’d like to let you know how we solved it so you might consider adding the fix to the core code.

On Google console we restricted the API to our domain. We added the API key to the theme Panel and we noticed that we were getting 403 responses from the API.

We did some digging and it turns out wp_remote_get (which is used in /td-composer/legacy/common/wp_booster/td_remote_http.php in function get_url_wordpress() ) does not send the ‘Referer’ header by default (or it doesn’t send the correct details, not sure)

This caused the Youtube API to think we were sending our request from googleapis.com itself and would return 403.

To fix this we added the following after the twitter workaround in get_url_wordpress() (should be ~line 196)


if(!array_key_exists('Referer',$settings['headers']){
$settings['headers']['Referer'] = site_url();
}

Basically we check if a referer header is already set and if not, we add the site url as a referer.
This fixes the issue and shouldn’t cause any unintended errors elsewhere. It only changes things if what we’re trying to set does not already exist.

Also, sidenote, I noticed you’re setting sslverify to false, you might want to consider changing that to true. See more details here -> SSL Verify

Thanks!

Post count: 21065

Hello!

We will test it too and if we consider this is a fix we will implement in our future updates.
We will take in consideration your query.

Thank you!

Viewing 2 posts - 1 through 2 (of 2 total)
The forum ‘Newspaper’ is closed to new topics and replies.