我已经注册了谷歌 Cloud 平台的免费试用 . 我创建了一个项目和 OAuth 2.0 client IDs . 我也得到了一个json文件 . 我安装了所需的软件包
pip install --upgrade google-api-python-client
pip install google-cloud
现在我需要在我的python程序中从google访问图像API中的文本提取 . 我的代码是(here)
from google.cloud import vision
client = vision.Client()
with open('./image.jpg', 'rb') as image_file:
image = client.image(content=image_file.read())
texts = image.detect_text()
print texts[0].description
我有JSON文件,客户端ID,客户端密码 . 如何在上面的代码中集成这些信用来访问google api?
1 回答
假设您想要在App Engine上本地访问 Cloud 视觉API,它应该“正常工作” .
要使用服务帐户JSON密钥文件进行身份验证,您需要使用环境变量指向它:
您也可以使用Google Cloud SDK进行身份验证(如果可用)
https://googlecloudplatform.github.io/google-cloud-python/stable/google-cloud-auth.html#overview