如何在Databricks Python Notebook中输入GoogleapicLient授权代码
我已经在Databricks笔记本中写下了以下代码(只是它的问题部分):
# Connection
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
print(flow)
credentials = flow.run_console()
youtube_analytics = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
print(youtube_analytics)
# After this password would ask you to visit the url to authorize this application
# Youtube Project wants to access your Google account
我运行,它将我重定向到Google登录页面,我执行登录,获取授权代码,然后您被问到我被问到要“输入授权代码:”。 问题是i 无法进入条目/输入。在我的木星笔记本电脑中,它使我有可能仅在单元格输出中输入验证代码。
但是,使用Databricks笔记本电脑,它似乎一直在等待代码输入。输出如下:
<google_auth_oauthlib.flow.InstalledAppFlow object at 0x7f3b921665b0>
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=123456789012-2jk0lelmg5m4p5s6c0b284potst9cumd.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyt-analytics.readonly&state=EBizXejyThoJCSszfypDsqczBSN2Tk&prompt=consent&access_type=offline
Enter the authorization code: (*here I can't input the code)
I have written the following code in Databricks notebook (just the problematic part of it):
# Connection
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
print(flow)
credentials = flow.run_console()
youtube_analytics = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
print(youtube_analytics)
# After this password would ask you to visit the url to authorize this application
# Youtube Project wants to access your Google account
I run it, it redirects me to google sign in page, I perform a sign in, get an authorization code, and as you see I am then asked to 'Enter the authorization code: '.
The problem is I can't make the entry/input. In my Jupiter notebook it gives me a possibility to enter the auth code just in console output of the cell.
However, with Databricks notebook, it appears to be constantly waiting for the code input. Output is below:
<google_auth_oauthlib.flow.InstalledAppFlow object at 0x7f3b921665b0>
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=123456789012-2jk0lelmg5m4p5s6c0b284potst9cumd.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fyt-analytics.readonly&state=EBizXejyThoJCSszfypDsqczBSN2Tk&prompt=consent&access_type=offline
Enter the authorization code: (*here I can't input the code)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

所以我找到了解决方案。
首先,我仍然不知道如何在Databricks中进行输入,但是我发现了如何避免执行它。
您只需打开其他平台,例如木星笔记本,在此处运行所有代码,包括下面的代码:
复制输出后,创建一个带有此输出的JSON文件,并将其称为“例如Token .json“。它必须看起来像下面的一个:
然后将“ token.json”上传到 databricks workspace ,然后在此处编写以下代码:
现在应该使用。它对我有用,但我不假装非常准确。问任何问题或纠正我。
So I have found a solution.
Firstly, I still do not know how to make an input in Databricks, but I have found how to avoid performing it.
You can just open some other platform, for example Jupiter notebook, run there all the code including the one below:
After this copy the output, create a json file with this output and call it for example "token.json". It must look something like the one below:
Then upload "token.json" to Databricks Workspace and then write the following code there:
And now it should work. It works for me, but I do not pretend to be very accurate. Ask any questions or correct me.