philbot9/youtube-comments-task

ERROR Button is missing attribute "data-token"

Closed this issue · 5 comments

Module doesn't work. Tried with simple example from readme.

Hi there,
Thanks for opening an issue. The example works fine for me.

Could you check whether the video I used in the example is available in your country?https://www.youtube.com/watch?v=h_tkIpwbsxY

If it's not, that would explain why you're getting an error. You could also try with a different video to see if that works.

Hi, thanks for reply.

Sorry I didn't mention it. Yes, video is working and i tried with another videos.

Code is basic

console.log('Testing....');

const fetchComments = require('youtube-comments-task')

fetchComments('h_tkIpwbsxY')
  .fork(e => console.error('ERROR', e),
        p => {
          console.log('comments', p.comments)
          console.log('nextPageToken', p.nextPageToken)
        })

On running

DEBUG=* node app.js

result is this

request sending request: 'https://www.youtube.com/watch?v=h_tkIpwbsxY' +0ms
  request sending request: { method: 'POST', json: true, url: 'https://www.youtube.com/watch_fragments_ajax?v=h_tkIpwbsxY&ctoken=EhYSC2hfdGtJcHdic3hZwAEAyAEA4AEBGAY%3D&frags=comments&tr=time&distiller=1&spf=load', form: { session_token: 'QUFFLUhqbUxnZmhmVFMxaVAycERBODlGSHFkUDktalhWd3xBQ3Jtc0tuamVGRGMybHQwOFh3Y2IxcjUwWFZwM1VLTlZHdGprTmI4WnJ1RHZUQl9YcVYtRi1HMllqaWtfUW9XSHhZdGtPVXpUUFpYckJCeHVlaUVJb0xPNkE3Tm9IWnM3UTR4c3R2MDdPV0NyZ1FEd0pydGRWNjhmalVCanFnN25CNk16MnE5YkZvNjZKZUNPbjlFaUdfbHJPYjlQM2d5Nnc=', page_token: undefined } } +599ms
ERROR Button is missing attribute "data-token"



PS. I also tried youtube-comment-api, which worked. Is there a reason you used different approach here ( different request urls etc. ) ?

Interesting. Thanks for posting the code, always helps.

The youtube-comment-api module is a lot older than this one. When I wrote this new module YouTube had switched to different URLs and slightly different mechanisms for the comments. However, the old mechanisms that the youtube-comment-api uses still work.

I've tried your code, with a fresh npm install youtube-comment-tasks and it is working for me (I know, not much of a consolation). At this point, I am unclear as to why you're getting that error since I cannot reproduce it. Because you mentioned the old system still works, my best guess is that the new YouTube comment system is unavailable in your location.

Am I correct in assuming you're not in North America? Would you mind sharing what country you're trying this from? I'd like to see if my guess is correct using a VPN or something.

I would recommend you use youtube-comment-api for now. If you'd like to use Tasks you could use the Futurize Promise Wrapper (I haven't confirmed whether that's working though).

Well, since it's working for you, problem could be our Southern European Gremlins.

Thanks anyway.

Yeah, the good old Localization-Gremlin strikes again. ;)

Turns out I wasn't too far off with my guess, albeit a much simpler problem. When requesting a comment page from any country, the results are translated to the language of that country. The problem was with this CSS selector: button[data-menu_name="newest-first"].

The data-menu_name attribute changes with different languages, which means the selector no longer works. Fortunately, when sending requests with the Accept-Language=en HTTP header YouTube sends English content, no matter where you are.

Commits 640040e and 053b64e should fix this problem. I also pushed the fix to npm.

Thanks for your help in sorting this out.