2

我正在从 SQL api 迁移到用于谷歌融合表的新 API v1。我正在使用谷歌 api python 库。我已经完成了迁移步骤,但仍然遇到 oauth 问题。我需要进行服务帐户身份验证并设置了一个。我根据此处给出的示例对身份验证进行了建模:http ://code.google.com/p/google-api-python-client/source/browse/samples/service_account/tasks.py

这是我的代码:

# Read in private key                                                                                                                                                        
f = file(KEY_FILE,'rb')
key = f.read()
f.close()

# Create an httplib2.Http object to handle our HTTP requests and authorize it                                                                                                
creds = SignedJwtAssertionCredentials(API_EMAIL, key,   
    scope='https://www.googleapis.com/auth/fusiontables')
http = httplib2.Http()
http = creds.authorize(http)

print vars(http.credentials)
service = build("fusiontables", "v1", http=http)

result = service.query().sql(sql="SELECT rowid, Title FROM "+TABLE_ID+" WHERE
ID="+str(id)).execute()

response = service.query().sql(sql="DELETE FROM "+TABLE_ID+" WHERE 
ROWID='"+result["rows"][0][0]+"'").execute()

select 语句有效,但随后 delete 语句出现 403 Forbidden 错误。打印语句显示空凭据。

Traceback (most recent call last):
File "test_oauth.py", line 36, in <module>
response = service.query().sql(sql="DELETE FROM "+TABLE_ID+" WHERE
ROWID='"+result["rows"][0][0]+"'").execute()
File "/lib/google-api/oauth2client/util.py", line 120, in positional_wrapper
return wrapped(*args, **kwargs)
File "/lib/google-api/apiclient/http.py", line 680, in execute
raise HttpError(resp, content, uri=self.uri)
apiclient.errors.HttpError: <HttpError 403 when requesting
https://www.googleapis.com/fusiontables/v1/query
alt=json&sql=DELETE+FROM+xxxx+WHERE+ROWID%3D%27239601%27 returned "Forbidden">

我能够从 API 资源管理器运行这些语句没问题。任何帮助表示赞赏,谢谢!

4

0 回答 0