The YouTube Data API (v2) has been officially deprecated as of March 4, 2014. The next version is the v3.

AFAIU this module is using the v2. (In the module, the REST API url is set to https://gdata.youtube.com/feeds/api/videos, different from v3 and the Youtube search video function media_youtube_video_search() is explicitly using version 2 of the API )

Beside the fact that the search feature and the video id validation might stop working one day, it doesn't stimulate developers to bring new features in this module.

Google is (naturally!) claiming that the V3 is simpler, yet more powerful than the V2. However, apparently not every features of V2 have been migrated yet (Details on the deprecation FAQ). And another important difference is that v2 supported anonymous API access for read-only queries, v3 doesn't.

Has anybody work on a Youtube API v3 integration ?

Comments

gabriel.achille’s picture

I developed a sandbox module to test the YouTube API V3 integration: gabriel.achille's sandbox: Media YouTube extra.

Currently it is still using API v2 for the existing services (search video and check video id). I have added v3 support for other features like retrieving YouTube video metadata: views count, video duration and published date.

cameron prince’s picture

It seems that the v2 API is no longer available. When searching for a YouTube video now, only a single result is shown with the message:

https://youtube.com/devicesupport

"Youtube is upgrading to a newer version, which is not supported by this device or app. To learn more and see where you can watch YouTube, visit www.youtube.com/devicesupport"

The same is affecting the YoutubeChannel module. See https://www.drupal.org/node/2474977

cameron prince’s picture

Title: YouTube API v3.0 upgrade (v2 deprecated) » YouTube API v3.0 upgrade (v2 deprecated - www.youtube.com/devicesupport)
Category: Feature request » Bug report
Priority: Normal » Critical
opstao’s picture

The specific way this is failing in my site is that all the youtube thumbnails in a View are being replaced by the youtube error-message image, and links fail to open in a previously working Colorbox display. However the video still plays when launched from the full content page link.

What is the prediction about how and when this can be resolved to coordinate with the revised API?

zonesny’s picture

StatusFileSize
new2.77 KB

Hi. I made some very quick modifications to the media_youtube.module file, and seem to have it functioning again (ie pulling videos from youtube and displaying and saving via the media browser). Mainly, I modified the media_youtube_video_search() function (added parameters, including my API key), and media_youtube_add() function. I also changed the MEDIA_YOUTUBE_REST_API and parsed the JSON result instead of XML. Ideally, the API Key should be stored the way the gabriel.achille does it in his sandbox module: media_youtube_extra (via the media_youtube_extra_settings_form). Disclaimer: I have not done extensive testing on these changes. I merely wanted to see if I could get the module operational again. Please feel free to further test and improve this down and dirty version. Thanks.

opstao’s picture

Just to provide a report on how the interim patch is working: Links from youtube thumbnails displayed in a view are now playing in a Colorbox window as intended, and all videos in the view play consecutively (upon manual advance) as intended. However the actual thumbnail in the view is still displaying the youtube "/devicesupport" error and refreshing or cache clearing doesn't resolve it. At least the video play function is working from all places where it should, from the view or from the full content page.

zonesny’s picture

Hi OpsTao. Thanks for the feedback on the patch. I'm not familiar with the Colorbox module. Are you receiving any errors in the log that you can post here for debugging purposes?

opstao’s picture

Issue tags: +media youtube
StatusFileSize
new21.93 KB
new167.52 KB

Colorbox is just a lightbox-type display thing, similar to the Lightbox2 module. The view is configured to display youtube thumbnail images which also serve as links to play the video; it it configured to open the video in a Colorbox modal window. (See uploaded image "view_colorbox_setup.png.") After the patch, that play function is working; before the patch it was not.

The view continues to display the error-message image. (See image "youtube_error.") However if the video title is clicked to open the full content page, the video field displayed there is correct and the video can be played in the page. (No Colorbox display used there.) I admit I made the mistake of using a module "Image Style Flush" in an attempt to fix this problem. At the point when youtube officially disabled the previous API last week, only the most recently uploaded video had this error. In an attempt to refresh all the thumbnail previews, I tried this module. The result was losing all the previews and replacing them with this error image. Before that, I had only one error and the older ones were still working, presumably because they were cached as Image Styles.

Errors in Log: I cleared the log then tried reloading the page in question (the view page) several times, but no error is generated. I don't know if there was an error before the patch was applied. In order to check that I would need to go back to the unpatched version.

zonesny’s picture

StatusFileSize
new6.07 KB

Thanks for the screenshots. To clarify, are the "device error" thumbnails related to videos you've created since applying the patch? If these are older videos (i.e. the error thumbnail was presumably saved with the video file), then you'll need to remove and re-load each video.

In the interim, I've updated the patch (with gabriel.achille's code, minus the cache) so that the API Key is now entered via 'admin/config/services/media-youtube'. The attached patch and the previous one are identical except for the API key changes.

opstao’s picture

I applied the _v2 patch and installed the patched module. As a test, from the youtube account I deleted one video, uploaded a replacement, and entered the new URL in the site page for that video. The play function as described before is still OK, but no improvement in the display of the youtube thumbnail that was previously working in the view. (still the "/devicesupport" error)

zonesny’s picture

StatusFileSize
new6.11 KB

Apologies, I just spotted an error in version two of my patch: the api key was being referred to in media_youtube_video_search(), as 'media_youtube_extra_api_key' instead of as 'media_youtube_api_key'. Here is a revised version (v3).

OpsTao, do you have media_youtube_extra sandbox module installed? I'm thinking It should have failed to fetch a video for you, if the api key (called in variable_get()) was incorrect. Thanks.

deadbeef’s picture

StatusFileSize
new5.82 KB

Rerolled v3 patch to apply with -p1 and removed erronous .DS_Store references.

opstao’s picture

StatusFileSize
new38.57 KB

I installed the _v4-patched module. The only problem continues to be in the youtube thumbnails that previously worked in a View that displays all content of type "work sample: video." The View still displays the youtube error image.

The uploaded image shows more of that View configuration. If I change the formatter from "youtube thumbnail" to "youtube video" then the View will successfully display the video and it is playable from the View. (But that is not what is desired here.)

Considering what was changed in this latest patch, do you think it would still be necessary to delete the videos from the youtube account, re-upload them, and re-enter the revised URL in the Drupal content page?

zonesny’s picture

Hi OpsTao. The patches (versions 1-4) are essentially the same. In v2, I added a configuration form (courtesy of gabriel.achilles' code) so that the API key could be entered cleanly and saved in the variable table. In V3, I fixed an error in the code: an incorrect variable name. In V4, deadbeef re-rolled the V3 patch with the correct diff -p1 option and fixed a reference to meta files that Mac OS inserts (.DS_Store). (Thanks deadbeef.)

Unfortunately, I'm unclear if the issue you're experiencing with the Colorbox module is due to the way that the thumbnails are being cached (which is why I suggested deleting and re-saving the videos). You mentioned that if you change the formatter, the view successfully displays the video, so it sounds like in the "youtube video" format the thumbnail and video work correctly. I will see if I can play with Colorbox module this week to investigate, but it would help if we were seeing something in the logs.

opstao’s picture

zonesny, thanks for the explanation of what's been done so far. I don't think the problem is related to Colorbox because the playback in Colorbox windows is now correct (since the first patch level), exactly as it was before Google's API change when it started behaving badly. The youtube error "devicesupport" is only occurring in a standard Drupal view image field, and it is only the youtube thumbnail (a function provided by Media: Youtube) that is not working as it once was. Summarizing: in the view's image field formatter the option "youtube video" works OK but "youtube thumbnail" does not.

I checked the log again after purging it and going to that page several times, but unfortunately nothing is registered.

drupalnewie @berfi’s picture

i am using feeds_youtube parser to get the recent youtube videos to my website. I tried to filter devicesupport error using the views module but i haven't been able to prevent the error from displaying on my site.

marcelovani’s picture

Status: Active » Needs review
StatusFileSize
new5.66 KB

humm Looks like patch #12 was done against a release tag, it doesn't apply using git or make file. I have re-rolled it from dev branch, this should apply cleanly.

i.e. this should not be there

 version = "7.x-2.0-rc5"

I also removed some white spaces.

marcelovani’s picture

Now that the patch is applying I am testing the functionality.
I haven't set the key via UI and when I tried to add a video I get this error

Exception: Error Processing Request. (Error: 400, Bad Request) in media_youtube_video_search() (line 367 of

zonesny’s picture

Hi marcelovani. Thanks for re-rolling against dev branch. The API key is required to make any calls. Hence, the Bad Request error.

marcelovani’s picture

I have added a check to display a friendly message to the user instead of that Exception
It contains the explanation and links to the API documentation and the configuration page.

Also, I have changed the url for the configuration to make the Media: Youtube configuration page appear on the same page as Media module, hope you agree with that, otherwise I can revert it.

Attaching screenshot of the friendly message, patch and interdiff.

Status: Needs review » Needs work

The last submitted patch, 20: media_youtube_apiv3_v20.patch, failed testing.

maxmendez’s picture

Thanks everyone for their work in this issue, here it's my small contribution.

I fixed the last patch.

maxmendez’s picture

Status: Needs work » Needs review

The last submitted patch, 5: media_youtube_apiv3_v1.patch, failed testing.

The last submitted patch, 9: media_youtube_apiv3_v2.patch, failed testing.

The last submitted patch, 11: media_youtube_apiv3_v3.patch, failed testing.

The last submitted patch, 12: media_youtube_apiv3_v4.patch, failed testing.

opstao’s picture

When applying patch -21 using same method as with previous patches, I get this error:

patching file media_youtube.info
Hunk #1 FAILED at 8.
1 out of 1 hunk FAILED -- saving rejects to file media_youtube.info.rej

I am applying to 7.x-2.0-rc5, is this correct?

maxmendez’s picture

Sorry, the patch was created to the version 7.x-2.x-dev

opstao’s picture

Tried patching 7.x-2.x-dev but got same error. Suggestions? No errors with previous patches. Using Terminal in Mac OS.

marcelovani’s picture

Patches should always be against dev version
to apply:

  1. checkout the module
  2. git apply name.patch

patch #22 is passing the test and applies with no errors for me

sophiejones’s picture

Hello
When applied patch #22 (last submitted patch) I too get the error in regards Hunk #1 failed at 8
But I do get the option to add youtube api which I did so I proceeded to test it and see. It works and I am getting the thumbnails in the view but with one difference. I used to get more option than I do now.
I searched for a singer that I knew has a lot of video and I only received 6 option. So is this what this new api is doing?? limiting options?? or is this due to the error I got when applying the patch??
I can see why google is doing this. they can now charge for its usage after certain quota.
Sorry I don't have as much knowledge as most of you about codes , I appreciate any input about this.
regards

marcelovani’s picture

StatusFileSize
new6.54 KB

I have re-rolled the patch and tested.
It works with no errors.
If it doesn't work for you, you must be doing something different than #31

zonesny’s picture

Hi All,
Two things:
1) In answer to sophiejones' query, by default the new API only returns 5 results. Sheesh. To correct this, we'll need to add the maxResults parameter in media_youtube_video_search():

$options['maxResults'] = 50; //perhaps this should be configurable?

The <em>maxResults</em> parameter specifies the maximum number of items that should be returned in the result set. [...] Acceptable values are 1 to 50, inclusive.

2) While I haven't yet applied the latest patch, I've recently started getting the same error as marcelovani in my local environment:
Exception: Error Processing Request. (Error: 400, Bad Request) in media_youtube_video_search() (line 397 of /Applications/MAMP/htdocs/drupal/sites/all/modules/media_youtube/media_youtube.module). I'm wondering if this is because I am using the same API key in Production, and if YouTube captures the IP and restricts usage?? Has anyone else experienced this?

zonesny’s picture

I created the attached patch against latest dev to address the 'maxResults' issue in #34 (it's configurable via the form in 'admin/config/media/media-youtube'). Also, I added $request->data to the Exception thrown in media_youtube_video_search() function, since it's impossible to tell the cause of these errors without seeing the full response body. Feel free to change as the group deems best, just trying to keep going in the right direction. Thanks.

opstao’s picture

I am still getting the patch error "Hunk #1 FAILED at 8." At the risk of being too elementary, I will describe exactly what I do. Maybe someone can explain why this procedure hasn't worked since patch -21 but worked before that.

  1. download and extract to local drive: media_youtube-7.x-2.x-dev
  2. download patch, exactly as named here: media_youtube_apiv3_v34.patch
  3. move patch inside module directory, top level
  4. open Mac terminal, type cd and drag the extracted module folder there and hit return, thus going to correct directory
  5. paste copied patch name into terminal: patch < media_youtube_apiv3_v34.patch and hit return
  6. upload/replace complete modified media_youtube module directory to directory sites/all/modules

In any case I am looking for confirmation from anyone who has success with the patch: Does it solve the problem with youtube thumbnails being replaced (just recently) with the youtube "devicesupport" error image? Is the Google API key necessary if all you're trying to do is display individual videos in a site, not contents of a channel?

zonesny’s picture

Hi OpsTao. My patch (#34) was created using Git, and I think you'll continue to get the "Hunk #1 Failed at 8" because the version downloaded from the media_youtube module page (i.e. the dev zip/tar file) is not identical to code on Git. The only difference is probably the .info file, as the zip/tar adds the following lines:

; Information added by Drupal.org packaging script on 2015-03-23
version = "7.x-2.0-rc5"
core = "7.x"
project = "media_youtube"
datestamp = "1427094782"

The best way to patch is to install Git and follow these directions:
Media_YouTube git instructions

Alternatively, you could manually apply the patch (i.e. for each affected file, wherever you see a minus, you will delete that line, and wherever you see a plus, you'll add that line of code). However, this is tedious and prone to error.

The patch is working for me (i.e. allowing me to search, select, save and play videos via the media browser with the correct thumbnails), but I'm not using Colorbox or Feeds. One note: the pagination for the media browser still needs to be fixed. In other words, the "previous" and "next" links are not operating correctly.

cameron prince’s picture

StatusFileSize
new7.01 KB

Here's a re-roll that solves the hunk failed error on media_youtube.info.

Status: Needs review » Needs work

The last submitted patch, 38: media_youtube-apiv3-2410027-38-D7.patch, failed testing.

cameron prince’s picture

StatusFileSize
new7.12 KB

Cleaned up whitespace and spelling errors.

cameron prince’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 40: media_youtube-apiv3-2410027-39-D7.patch, failed testing.

zonesny’s picture

Patch #34 passed testing and applies cleanly via Git. No need to re-roll, just use Git to apply patch.

marcelovani’s picture

Guys, you cannot work with patches on downloaded zip files.

There are instructions on how to create patches here https://www.drupal.org/project/media_youtube/git-instructions

Which is as simple as

git pull origin 7.x-2.x
git diff >  [description]-[issue-number]-[comment-number].patch 

I like the option to specify the number of items.
Can someone else review patch 34?

SoportePRO’s picture

Using patch from #35, I manually modify the patch lines in the media_youtube.info and media_youtube.module from release (7.x-2.0-rc5) files and ALL works ok.

In the line 514 aprox. this is the correct permission:

'access arguments' => array('administer media'),

Unset /set the module or clear all caches to enable changes.

Do not forget to get your Server Public Api key from Google developers console and enable Youtube API.

Go to your new media menu option (admin/config/media/media-youtube) add your api key and save.

Verify that Database "variables" table have stored the API key value.

cameron prince’s picture

StatusFileSize
new6.86 KB

I didn't realize the patch in #35 was against the zip file... Here's an update based on instructions from #44.

cameron prince’s picture

Status: Needs work » Needs review
cameron prince’s picture

I'm really stumped here... I followed the instructions at https://www.drupal.org/project/media_youtube/git-instructions explicitly and the patch passed testing, but still won't apply to either the current of dev versions of the module, downloaded with drush.

# git apply -v ~/media_youtube-apiv3-2410027-46-D7.patch 
Checking patch media_youtube.info...
error: while searching for:
files[] = includes/MediaYouTubeStreamWrapper.inc
files[] = includes/MediaInternetYouTubeHandler.inc
files[] = includes/MediaYouTubeBrowser.inc

error: patch failed: media_youtube.info:8
error: media_youtube.info: patch does not apply

How is this possible?

cameron prince’s picture

StatusFileSize
new6.87 KB

So I moved the new line being added to media_youtube.info above the files[] declarations and now it applies cleanly.

cameron prince’s picture

Status: Needs review » Reviewed & tested by the community

I just tested the patch on dev and then pushed up to production. It works great. Thanks and nice work zonesny!

zonesny’s picture

Sure. Just to clarify my patch (#34) was created against Dev branch via Git, so it should only be applied against Dev.

Also, we still need to fix the pagination code (ie previous and next links).

opstao’s picture

Sorry to drag this out more, but I am still having trouble. I applied media_youtube-apiv3-2410027-49-D7.patch to media_youtube-7.x-2.x-dev and there were no patching errors. It was uploaded to my site server to overwrite existing. I am still getting the youtube /devicesupport error image in fields that should be displaying the youtube thumbnail. (That's a view for picking up a few fields from all content type pages containing a single video with associated info.) Clearly it is gaining access to the youtube URL because the video can be played from 2 different places:

  1. in a lightbox-type display, upon clicking the thumbnail in the view (still works despite the thumbnail being that error image thing);
  2. within the page, on full content pages.

In case this comes up: The error appears for both Admin and a test authenticated user. Admin has all possible permissions. The site has no Commerce modules and doesn't have Rules.

One part of this process I didn't understand is about the Google API key. I implemented that, perhaps incorrectly, but should that still be necessary for this kind of youtube usage? If so, please confirm or correct the following assumptions I made:

  1. type of key generated: “Key for server apps (with IP locking)”
  2. IPs: Any IP allowed
  3. generated key copied and pasted into Configuraton>Media>Media: Youtube>API key

---Thanks for any suggestions---

cameron prince’s picture

OpsTao, I don't have a use case similar to yours, but I wonder if it's a thing that isn't retroactive. Can you confirm that newly created content has the same issue?

The key process you describes matches what I did, as best I recall.

opstao’s picture

cameronbprince, I tried your suggested test with the patched module deployed. I created a new item of my content type "work sample: video" and using a different youtube URL (from my collection) than any previously used ones. The new item displays in the view, but again has that annoying error-message image. So, still stuck. But thanks for the suggestion.

This all worked perfectly, about 2 weeks ago!

dgtlmoon’s picture

+1, Patch from #49 applied cleanly against 7.x-2.0-rc5 aswell as dev and fixed the issue for me, I just had to add my new API key and all was good

galayant’s picture

Hello,

Do you know when this patch will be integrated in an stable version?

Regards,

opstao’s picture

I did some further testing by creating new content from a new content type using the same fields as used before. The conclusion is that although youtube videos are playing successfully, the youtube thumbnail option does not work in the most recent version (dev + patch 49). I am hoping that will also be addressed so we can get back to the full functionality available before Google disabled it with their API modification.

rooby’s picture

If this is good to go (I haven't tested yet) maybe we should create a stable release with whatever is in dev, then commit this to dev, then open follow up issues to fix anything extra like #57 before making a new release.

dgtlmoon’s picture

@optsTao: no problems with the thumbnails here, check your permissions, worked perfectly

devin carlson’s picture

Status: Reviewed & tested by the community » Closed (won't fix)
Related issues: +#2072327: Spin off YouTube search tab into a separate module

I removed the search tab with #2072327: Spin off YouTube search tab into a separate module in order to get out a new release.

v3 of the YouTube API should be handled using the official Google API PHP Client (see the 7.x-2.x branch of the Google Calendar Block module for an example) which provides a Google_Service_YouTube_Search_Resource class with various "search" methods.

I'd like to see search handled in a better way, either through enhancements to the Media Internet submodule or as a stand-alone project with plugins/submodules for each search provider (YouTube, Vimeo, etc). Search represented about 50% of the codebase, doesn't integrate with the rest of Drupal (views, media, etc) and was the source of the majority of the bug reports.

If someone provides a working project/sandbox then I'll add a link to it in the release notes and on the project page.

gabriel.achille’s picture

Agreed, using the official Google API PHP Client should save time and avoid bug.

I noticed as well that the (MediaInternetYouTubeHandler::validId) function is using the Youtube implementation of oembed format service to check whether or not the entered Youtube ID is valid. However Google is very discreet about it (Actually I couldn't find any information on Google related websites about that), cannot tell if it is API V2 or V3 or something else.
Does someone have any info on that and is it still reliable to use in this module ?

opstao’s picture

Back to the youtube thumbnail issue, since I have never been able to get this to work after the API change and module updates/patches. A question to users who are finding it's working for them: Are you sure it's not just hanging onto a cached image style thumbnail? (Not removed in "Flush all caches.") In my case I thought everything was working until I used the image style flush module, after which everything changed to the youtube "devicesupport" error image and never returned. If thumbnails from newly added videos are working, that would confirm it's working. If yes, then I still need to find out why it's not working in my site and I will appreciate any specific troubleshooting suggestions.

rooby’s picture

Side note:

An alternative to the image style flush module is to just delete the contents of the image styles directory and then they will regenerate.

opstao’s picture

@rooby, that is true, but the point is not about clearing that cache. Maybe I shouldn't have cleared it at all. But by doing so, it uncovered the fact that the youtube thumbnails are no longer working as they did before and being delivered "fresh" from the account uploads list. (Well, in my site configuration they're not.) So I am hoping to get a suggestion about why that function is not working whereas video play function is working fine.

UPDATE: Finally got this perplexing problem solved, although the logic behind it still eludes me. A new image style was created and assigned to the display of the youtube thumbnail, then cache was cleared. Now working as it did before the API revolution. If I go back to the image style being used before, the error images return. (Probably because they're cached – but those had been deleted several times previously, only to return.) Anyway, it took a new image style to “escape” from the error images.

Chris Charlton’s picture

Checking in to see what this ticket needed, 2 years later. Is this ticket just stale or outdated?

ankitsingh0188’s picture

Status: Closed (won't fix) » Needs review
StatusFileSize
new7.72 KB

Hello,

I have created a patch for that and test it.
Please find the attached patch. The patch search the youtube videos accordingly

Note : You can add the YouTube API Url and API Key from here : admin/config/media/media-youtube

Thanks!

ankitsingh0188’s picture

ankitsingh0188’s picture

joseph.olstad’s picture

I've been granted co-maintainer access, if you want to help out, please make a wishlist for me in a new issue with references to the patches that are ready to commit.

ankitsingh0188’s picture

Hi Joseph Olstad,

I have created the issue for the same and upload the patch which needs to be tested.

Reference link : https://www.drupal.org/node/2883216#comment-12112687

Thanks!

joseph.olstad’s picture

Hi Ankit.singh , your patch does not apply on the media_youtube 7.x-3.x branch , does your patch depend on some other patches?

according to your patch there is a file called js/media-youtube.browser.js
however I do not see this file in the 7.x-3.x branch

also, it appears you've made the patch against profiles/ttrybe ....
the correct way to make a patch is by cloning the project, in this case media_youtube , applying your code changes and then capturing the changes as you normally would using git diff for example.

joseph.olstad’s picture

ah , sorry , just noticed that the patch was for the 7.x-2.x branch , makes sense, however the patch needs reroll anyway, its not formatted correctly

joseph.olstad’s picture

Status: Needs review » Closed (duplicate)