Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request fails without the __Secure-1PSIDTS cookie #29

Open
nerblock opened this issue Jul 14, 2023 · 9 comments
Open

Request fails without the __Secure-1PSIDTS cookie #29

nerblock opened this issue Jul 14, 2023 · 9 comments

Comments

@nerblock
Copy link

The value of __Secure-1PSIDTS (or __Secure-2PSIDTS, __Secure-3PSIDTS, etc, depending on the user number) must be included in the cookie. This is what the cookies variable should look like in order to make a successful request:

let cookies = `__Secure-1PSID=<COOKIE_VALUE>; __Secure-1PSIDTS=<COOKIE_VALUE>`;

When it is not included (as described in the current readme) the request fails with this error:

Error parsing response: make sure you are using the correct cookie, copy the value of "__Secure-1PSID" cookie and set it like this:

new Bard("__Secure-1PSID=<COOKIE_VALUE>")

Also using a US proxy is recommended.

If this error persists, please open an issue on github.
https://github.com/PawanOsman/GoogleBard
file:///C:/Users/user/Source/bard-test/node_modules/googlebard/dist/classes/bard.js:174
        return resData[3];
                      ^

TypeError: Cannot read properties of undefined (reading '3')
    at Bard.ask (file:///C:/Users/user/Source/bard-test/node_modules/googlebard/dist/classes/bard.js:174:23)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async file:///C:/Users/user/Source/bard-test/index.js:8:16
@piccolo20
Copy link

I did include those cookies and it worked then after 20 minutes the request fails again. What do you think?

@piccolo20
Copy link

Those cookies always change per 10mins

@nerblock
Copy link
Author

nerblock commented Jul 14, 2023

I guess they added this requirement to make programatically calliing the api more difficult.

@piccolo20
Copy link

Oh sorry about that. My fault keep refreshing my browser page and it generates new value. The code works well now.

@hugoroussel
Copy link

@nerblock thanks for creating this issue, by adding __Secure-1PSIDTS=<COOKIE_VALUE> I was able to make it work. However, I did not try to use __Secure-2PSIDTS or __Secure-3PSIDTS. Any way to generate those cookies programmatically?

@nerblock
Copy link
Author

You can use browser_cookie3.
Also check out this issue: dsdanielpark/Bard-API#99

@piccolo20
Copy link

@nerblock thanks for creating this issue, by adding __Secure-1PSIDTS=<COOKIE_VALUE> I was able to make it work. However, I did not try to use __Secure-2PSIDTS or __Secure-3PSIDTS. Any way to generate those cookies programmatically?

You can get them if you get the success response. The response has Set-Cookie:

@sturmenta
Copy link

@nerblock Did you find a way to get the __Secure-1PSIDTS cookie programmatically?

@Hecker5556
Copy link

Hecker5556 commented Nov 27, 2024

year too late but I'm experiencing something similar on youtube.
To refresh that cookie on youtube, you need to make an authenticated request to:
https://accounts.youtube.com/RotateCookiesPage?origin=https://www.youtube.com&yt_pid=1
you need to have most recent __Secure-1PSIDTS cookie when making a request to it
in there use regex to fetch the data string, which is in:
init('-5270579600125631160', 0.0, 1.0, 0.0, 600.0)
so youre getting the '-5270579600125631160'
example regex:

\(\'(\d+)\',

after that, you make an authenticated POST request to
https://accounts.youtube.com/RotateCookies
with json data being
[
None,
'-5270579600125631160',
1,
]
you should get status code 200, and you can directly access it from response.cookies.get("__Secure-1PSIDTS") (assuming you did response = requests.post)
in the case that youre using aiohttp, doing

async with session.post(...) as r:
    psid = r.headers.get("Set-Cookie")

the string from the first request should last a day, but I got no clue how to get it.
for this i'm pretty sure account.google.com should work instead of youtube

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants