TweePy - 如何隐藏 API 密钥 [英] TweePy - how to hide API key

查看:31
本文介绍了TweePy - 如何隐藏 API 密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建使用 Twitter API 的简单应用程序.我该怎么做才能隐藏我的 Twitter 应用程序密钥?例如,如果我将我的程序放到互联网上,而查看代码的人会知道我的消费者密钥、访问令牌等.如果我不将此信息包含在我的程序中,它将无法运行!

I am building simple app which is using Twitter API. What I have to do to hide my Twitter app keys? For example, if I will put my program to the internet and somebody who look up to the code will know my consumer key, access token etc. And if I not include this information into my program, that it won't be work!

推荐答案

我假设 放在互联网上 你的意思是在 github 上发布你的代码.

I'm assuming by putting on the internet you mean publishing your code on github or such.

在这种情况下,您应该始终将代码和配置分开.将您的 API 密钥放在 .ini 文件中,即 config.ini,然后使用 配置解析器

In that case you should always separate code and configuration. Put your API keys in an .ini file, i.e. config.ini, then load that file from python program using configparser

将配置文件添加到您的 .gitignore 中,这样它就不会被添加到源代码管理中.

Add configuration file to your .gitignore so it would not get added to the source control.

这篇关于TweePy - 如何隐藏 API 密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆