log in to Gmail/YouTube programmatically (+ YouTube API)

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 4811
Joined: 19 Dec 2016, 01:58
Location: UK

log in to Gmail/YouTube programmatically (+ YouTube API)

28 May 2017, 20:43

I'm planning to release various YouTube and YouTube API-related scripts and functions. I have everything sussed except actually logging in to YouTube.

Is there a way to log in to Gmail/YouTube directly without setting the text of and clicking web elements in Internet Explorer? Perhaps by using a url with username/password parameters or WinHttpRequest. Cheers.

To use the YouTube API in a passive way, e.g. to get a list of videos in a playlist, get a video's title/duration/date, get channel(/user) information, you don't need to log into Gmail/YouTube. But to make active changes to an account e.g. create a playlist, add videos to a playlist, you need to log in to Gmail/YouTube, and you need to click a button to confirm you want the API to be able to make changes to your account. So there are two logins required.

Btw some other sites of interest about which I might ask the same question: AutoHotkey, Stack Overflow, GitHub (although I don't use it yet), social media e.g. Twitter/Facebook/Instagram/Pinterest. Again, in IE, but not via set text/send click. Thanks.
BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

Re: log in to Gmail/YouTube programmatically (+ YouTube API)

29 May 2017, 09:55

https://github.com/h2non/youtube-video-api

Straightforward node.js/io.js programmatic and command-line interface to easily upload, list, update, rate, thumbnail and delete videos from YouTube using OAuth2 and Google API v3.

It was designed to provide a reliable server-to-server automation solution, with additional support for transparent Google API OAuth2 token negotiation retrieval using Nightmare + Electron in case that you don't have a valid OAuth2 token or simply you want to use a fresh token every time automatically


Hope that helps. I guess Electron/node.js has been dicussed already at this forum.
User avatar
jeeswg
Posts: 4811
Joined: 19 Dec 2016, 01:58
Location: UK

Re: log in to Gmail/YouTube programmatically (+ YouTube API)

05 Jun 2017, 21:03

Thanks for the link, good call. Despite looking through the code, and many Internet searches, I still haven't worked out how to login directly, without using Internet Explorer.

Here is the code I have so far:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
jeeswg
Posts: 4811
Joined: 19 Dec 2016, 01:58
Location: UK

Re: log in to Gmail/YouTube programmatically (+ YouTube API)

21 Jun 2017, 01:11

Any ideas? To log into YouTube directly, probably via COM, without using a web browser? To replace that bit of script I have highlighted above.

Once logged in, it is easy to do everything with the API via COM and JSON strings.

(I have had this problem for a very long time, and spent a lot of time on this. #years.) Thanks for reading.
User avatar
jNizM
Posts: 2318
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: log in to Gmail/YouTube programmatically (+ YouTube API)

21 Jun 2017, 03:08

jeeswg wrote:spent a lot of time on this. #years.

Than you should change your priorities in your life ;)
[AHK] 1.1.29.01 x64 Unicode | [WIN] 10 Pro (Version 1803) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jeeswg
Posts: 4811
Joined: 19 Dec 2016, 01:58
Location: UK

Re: log in to Gmail/YouTube programmatically (+ YouTube API)

21 Jun 2017, 04:52

@jNizM, have you fixed the problem yet? I hear you're pretty foxy when it comes to solving problems.
I have had this problem for a very long time ... #years.

I might try and install BoBo's suggested utility, and/or improve my login procedure which uses Internet Explorer. I would be interested in any other freeware for doing things like creating/adding to/editing playlists etc, and uploading videos. Of course it would have to do the logging in for you, i.e. just a straightforward command-line tool.

I might release some of my YouTube API functions within the next few months, I've been replacing some fiddly string handling with the use of Coco's JSON library, which will make it easier for others to understand, use and amend my functions, and to use them as a template for further functions.

Part of the problem is that ClientLogin was only deprecated 2 years ago, and IT problems typically take 5 years to emerge and become properly documented/discussed, and then a further 5 years to be fully resolved in multiple programming languages with good code examples.

==================================================

These links sum up the problem, there appear to be dozens of questions on Stack Overflow discussing the issue or consequences of it:

Migrating from YouTube ClientLogin to OAuth 2.0 - Stack Overflow
https://stackoverflow.com/questions/10490910/migrating-from-youtube-clientlogin-to-oauth-2-0

java - YouTube Data API: OAuth Authentication for services using V3 without user intervention - Stack Overflow
https://stackoverflow.com/questions/21057358/youtube-data-api-oauth-authentication-for-services-using-v3-without-user-interv/21100089#21100089

Move from ClientLogin to OAuth 2.0 | YouTube Data API | Google Developers
https://developers.google.com/youtube/v3/guides/moving_to_oauth#standalone
malcev
Posts: 88
Joined: 12 Aug 2014, 12:37

Re: log in to Gmail/YouTube programmatically (+ YouTube API)

21 Jul 2018, 06:14

You can login to Your Gmail like this:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
jeeswg
Posts: 4811
Joined: 19 Dec 2016, 01:58
Location: UK

Re: log in to Gmail/YouTube programmatically (+ YouTube API)

15 Aug 2018, 07:58

- Wow thanks so much. By saving the html that is produced at the end, and creating a file, it appears to confirm that the login works.
- Btw if you log in like this, it appears that you can't access Gmail/YouTube via Internet Explorer. It would be interesting if that were possible somehow.
- Since I can't manually log out of Gmail/YouTube, via Internet Explorer or another web browser, I'd need to log out programmatically. Do you have a script to do that? (Does it log out when the script ends?)
- How did you figure out this script? Thanks.

- Btw when I first tried to log in I got this error:
Verify it's you

This device isn't recognized. For your security, Google wants to make sure it's really you. Learn more

- Although the login appears to work, I haven't managed to get the login and then a YouTube playlist edit to occur. I will post my code for editing a YouTube playlist at some point, to see if anyone can marry the two together.
malcev
Posts: 88
Joined: 12 Aug 2014, 12:37

Re: log in to Gmail/YouTube programmatically (+ YouTube API)

15 Aug 2018, 11:14

Btw if you log in like this, it appears that you can't access Gmail/YouTube via Internet Explorer. It would be interesting if that were possible somehow.

It is possible through Msxml2.XMLHTTP because it uses the same cookies as IE.
Since I can't manually log out of Gmail/YouTube, via Internet Explorer or another web browser, I'd need to log out programmatically. Do you have a script to do that? (Does it log out when the script ends?)

Code: [Select all] [Download] GeSHi © Codebox Plus

url := "https://accounts.google.com/Logout"
HTTP.Open("GET", url, true)
HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko)")
HTTP.SetRequestHeader("Pragma", "no-cache")
HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
HTTP.Send()
HTTP.WaitForResponse()
msgbox % HTTP.ResponseText

How did you figure out this script

I turn off javascript in IE.
Turn off all buttons in Network tab in developer tools and start recording.
Then I login to my google account, stop recording and examine what I send to server and what receive.
User avatar
jeeswg
Posts: 4811
Joined: 19 Dec 2016, 01:58
Location: UK

Re: log in to Gmail/YouTube programmatically (+ YouTube API)

15 Aug 2018, 14:39

This is really interesting Malcev, thanks very much for the information. I will investigate further.

Return to “Ask For Help”

Who is online

Users browsing this forum: DarkACB, FanaticGuru, TAC109 and 46 guests