Google AppEngine带有服务帐户的Fusion Tables [英] Google AppEngine to Fusion Tables with Service Accounts

查看:100
本文介绍了Google AppEngine带有服务帐户的Fusion Tables的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在AppEngine上使用Python并尝试连接到/ v1 Fusion Table API带有Google服务帐户的Google Fusion Tables(使用JSON Web令牌的服务器端应用程序的OAuth2的更复杂的表亲)



我发现了另一个问题,在Google Prediction API中使用服务帐户。
Fusion Table和Google服务帐户



到目前为止,我已经得到了

 从oauth2client.appengine导入httplib2 
AppAssertionCredentials
from apiclient.discovery import build
$ b credentials = AppAssertionCredentials(scope ='https://www.googleapis.com/auth/fusiontables')
http = credentials.authorize (httplib2.Http(memcache))#Http(memcache)
service = build(fusiontables,v1,http = http)

#列出表格
表格= service.table()。list()。execute()#< - 错误401无效凭证在这里

有没有人有使用服务帐户连接到AppEngine上的Fusion Tables的例子,他们可能可以共享?或者在网上有什么好的?



谢谢

解决方案

。重要的部分是你必须让应用程序引擎服务帐户访问你的融合表。如果您正在编写该帐户,则需要写入权限。有关帮助,请参阅: https://developers.google.com/api-client -library / python / start / installation (寻找入门:快速入门)



您的应用引擎服务帐户类似于your-app-id @ appspot.gserviceaccount.com



您还必须在api控制台中将应用引擎服务帐户设为团队成员,并授予其可编辑权限。

  SCOPE ='https://www.googleapis.com/auth/fusiontables'
PROJECT_NUMBER ='XXXXXXXX'#用您的项目替换ID

#创建一个新的API服务来与Fusion Tables交互
credentials = AppAssertionCredentials(scope = SCOPE)
http = credentials.authorize(httplib2.Http())
logging.info('QQQ:accountname:%s'%app_identity.get_service_account_name())
service = build('fusiontables','v1',http = http,developerKey ='您的钥匙从AP I CONSOLE')

def log(value1,value2 = None):
tableid ='您的表格ID来自融合表'
now = strftime(%Y-%m - %d%H:%M:%S,gmtime())
service.query()。sql(INSERT INTO%s(Temperature,Date)values(%s,'%s' )%(tableid,value1,now))。execute()


Late to the game on migrating to the /v1 Fusion Table API but no holding off any longer.

I'm using Python on AppEngine and trying to connect to Google Fusion Tables with Google Service Accounts (the more complicated cousin of OAuth2 for server side apps that uses JSON Web Tokens)

I found another question that pointed me to some documentation for using Service Accounts with Google Prediction API. Fusion Table and Google Service Accounts

So far I've got

import httplib2
from oauth2client.appengine import AppAssertionCredentials
from apiclient.discovery import build

credentials = AppAssertionCredentials(scope='https://www.googleapis.com/auth/fusiontables')
http = credentials.authorize(httplib2.Http(memcache)) #Http(memcache)
service = build("fusiontables", "v1", http=http)

# list the tables
tables = service.table().list().execute() # <-- ERROR 401 invalid credentials here

Does anyone have an example of connecting to Fusion Tables on AppEngine using Service Accounts they might be able to share? Or something nice online?

Thanks

解决方案

This actually does work. The important parts are you have to give the app engine service account access to your fusion table. If you are writing then the account needs write access. For help see: https://developers.google.com/api-client-library/python/start/installation (look for Getting started: Quickstart)

Your app engine service account will be something like your-app-id@appspot.gserviceaccount.com

You must also make the app engine service account a team member in the api console and give it "can edit" privilege.

SCOPE='https://www.googleapis.com/auth/fusiontables'
PROJECT_NUMBER = 'XXXXXXXX' # REPLACE WITH YOUR Project ID

# Create a new API service for interacting with Fusion Tables
credentials = AppAssertionCredentials(scope=SCOPE)
http = credentials.authorize(httplib2.Http())
logging.info('QQQ: accountname: %s' % app_identity.get_service_account_name())
service = build('fusiontables', 'v1', http=http, developerKey='YOUR KEY HERE FROM API CONSOLE')

def log(value1,value2=None):
    tableid='YOUR TABLE ID FROM FUSION TABLES'
    now = strftime("%Y-%m-%d %H:%M:%S", gmtime())
    service.query().sql(sql="INSERT INTO %s (Temperature,Date) values(%s,'%s')" % (tableid,value1,now)).execute()

这篇关于Google AppEngine带有服务帐户的Fusion Tables的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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