Forum Archive

Webview , google api calendar 403 user agent issue

CastroSATT

Guys I’m like 3 weeks into learning python already built a BTC balance checker for an arcade machine with Arduino

So I’m kind of in love with pythonista....

Now for my next trick

I want to parse a CSV file then pipe the contents into a google calendar etc etc
After a time I found a solution to get real-time data rather than a saved CSV file so until I get that platform sorted I wanted to try and learn how to play with the google calendar... which is one half of the quest

So here’s the issue

Loaded python google bits as per instructions

Loaded up all the requirements and it’s seems to be working

-Using the standard Calendar QuickStart.py

The issue is I get a warning about please visit this url to auth

-click link

Brings me to pythonista web view

  • brings up and error 403

  • That’s an error.

Error: disallowed_useragent

Google can’t sign you in safely inside this app. You can use Google sign-in by visiting this app’s website in a browser like Safari or Chrome.

  • so I gatherd that’s it’s the user agent issue with pythonista and webview

So heres the question what do I do to clear it

Is it pythonista that’s needs to change or the scripts or an edit to the google python module

I will need this to obvs work all platforms ish

Also a decent explanation of what’s going on and where the issue

Please reply like I’m an idiot as I said, I’m super new to python but I am an all round tech so not completely useless

Thanks guys

-

JonB

You are not an idiot, Google just wants people to use their apis on mobile devices, rather than just use webviews. This might be for security reasons -- in a webview, a malicious app could modify the page to steal your password. Or else it is because it let's Google track you better. For whatever reason, Google therefore enforces limitations on which useragnts will work.

So, you have to spoof your useragent.

See

https://forum.omz-software.com/topic/4646/ui-webview-user-agent

For a function that gives you a custom useragent in a webview. You will have to look up what the right useragent is for desktop, or iOS using Google apis.

@mikael -- supposedly wkwebview has a custom useragent property that makes this easier. Does your wkwebview wrapper support that?

CastroSATT

Sorry dude need it plainer than that

So I saw the function but have no real idea on how to use this in conjunction with the test script

Either to do auth in another browser then hope it keeps that auth for google cal api
(I tried cut/paste with link ) got further but I think it saves an auth file which is meant to alter the cred.jsn or be saved along side
So when I went back into pythonista same error if feels like iam missing something

It feels like I have to change user agent of the webview/in built browser on pythonista It self not the code BUT the work around allows you to temp specify a user agent by adding the function to the google test script

If that’s the case I’m not sure where to go next “I am the idiot”

JonB

See
https://forum.omz-software.com/topic/4668/authorization-with-oauth/12

At the start of the thread, @mikael, has is approach to handling Google calendar. Read and try that first.

At the end, I posted a modified version of quickstart_web -- which you could use to get creds.json. you would need to modify the SCOPES to be correct for calendar (my example was for YouTube).

mikael

@JonB said:

@mikael -- supposedly wkwebview has a custom useragent property that makes this easier. Does your wkwebview wrapper support that?

It does now :-) There is a user_agent property that can be used to set a custom user agent string. I have not yet gotten it to return the default when custom is not set, but that is not relevant here.