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
Comment #1
gabriel.achille commentedI 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.
Comment #2
cameron prince commentedIt 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
Comment #3
cameron prince commentedComment #4
opstao commentedThe 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?
Comment #5
zonesny commentedHi. 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.
Comment #6
opstao commentedJust 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.
Comment #7
zonesny commentedHi 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?
Comment #8
opstao commentedColorbox 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.
Comment #9
zonesny commentedThanks 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.
Comment #10
opstao commentedI 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)
Comment #11
zonesny commentedApologies, 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.
Comment #12
deadbeef commentedRerolled v3 patch to apply with -p1 and removed erronous .DS_Store references.
Comment #13
opstao commentedI 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?
Comment #14
zonesny commentedHi 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.
Comment #15
opstao commentedzonesny, 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.
Comment #16
drupalnewie @berfi commentedi 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.
Comment #17
marcelovanihumm 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
I also removed some white spaces.
Comment #18
marcelovaniNow 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
Comment #19
zonesny commentedHi marcelovani. Thanks for re-rolling against dev branch. The API key is required to make any calls. Hence, the Bad Request error.
Comment #20
marcelovaniI 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.
Comment #22
maxmendez commentedThanks everyone for their work in this issue, here it's my small contribution.
I fixed the last patch.
Comment #23
maxmendez commentedComment #28
opstao commentedWhen applying patch -21 using same method as with previous patches, I get this error:
I am applying to 7.x-2.0-rc5, is this correct?
Comment #29
maxmendez commentedSorry, the patch was created to the version 7.x-2.x-dev
Comment #30
opstao commentedTried patching 7.x-2.x-dev but got same error. Suggestions? No errors with previous patches. Using Terminal in Mac OS.
Comment #31
marcelovaniPatches should always be against dev version
to apply:
patch #22 is passing the test and applies with no errors for me
Comment #32
sophiejones commentedHello
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
Comment #33
marcelovaniI 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
Comment #34
zonesny commentedHi 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?
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?
Comment #35
zonesny commentedI 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.
Comment #36
opstao commentedI 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.
patch < media_youtube_apiv3_v34.patchand hit returnIn 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?
Comment #37
zonesny commentedHi 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:
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.
Comment #38
cameron prince commentedHere's a re-roll that solves the hunk failed error on media_youtube.info.
Comment #40
cameron prince commentedCleaned up whitespace and spelling errors.
Comment #41
cameron prince commentedComment #43
zonesny commentedPatch #34 passed testing and applies cleanly via Git. No need to re-roll, just use Git to apply patch.
Comment #44
marcelovaniGuys, 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
I like the option to specify the number of items.
Can someone else review patch 34?
Comment #45
SoportePRO commentedUsing 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.
Comment #46
cameron prince commentedI didn't realize the patch in #35 was against the zip file... Here's an update based on instructions from #44.
Comment #47
cameron prince commentedComment #48
cameron prince commentedI'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.
How is this possible?
Comment #49
cameron prince commentedSo I moved the new line being added to media_youtube.info above the files[] declarations and now it applies cleanly.
Comment #50
cameron prince commentedI just tested the patch on dev and then pushed up to production. It works great. Thanks and nice work zonesny!
Comment #51
zonesny commentedSure. 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).
Comment #52
opstao commentedSorry 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:
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:
---Thanks for any suggestions---
Comment #53
cameron prince commentedOpsTao, 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.
Comment #54
opstao commentedcameronbprince, 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!
Comment #55
dgtlmoon commented+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
Comment #56
galayant commentedHello,
Do you know when this patch will be integrated in an stable version?
Regards,
Comment #57
opstao commentedI 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.
Comment #58
rooby commentedIf 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.
Comment #59
dgtlmoon commented@optsTao: no problems with the thumbnails here, check your permissions, worked perfectly
Comment #60
devin carlson commentedI 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.
Comment #61
gabriel.achille commentedAgreed, 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 ?
Comment #62
opstao commentedBack 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.
Comment #63
rooby commentedSide 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.
Comment #64
opstao commented@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.
Comment #65
Chris CharltonChecking in to see what this ticket needed, 2 years later. Is this ticket just stale or outdated?
Comment #66
ankitsingh0188Hello,
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!
Comment #67
ankitsingh0188Comment #68
ankitsingh0188Comment #69
joseph.olstadI'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.
Comment #70
ankitsingh0188Hi 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!
Comment #71
joseph.olstadHi 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.
Comment #72
joseph.olstadah , 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
Comment #73
joseph.olstadclose this in favour of:
#2883216: Youtube API Upgrade version to be integrated